Skip to content

Commit d403422

Browse files
committed
sock: use atomic_cas_ptr correctly
This bug was caused by incorrect documentation (already fixed). It resulted in us freeing the name on successful CAS and caching the freed pointer. Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent c6c4de7 commit d403422

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sock.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2019 Josef 'Jeff' Sipek <[email protected]>
2+
* Copyright (c) 2016-2020 Josef 'Jeff' Sipek <[email protected]>
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -60,7 +60,7 @@ const char *xgethostname(void)
6060
goto unknown;
6161
}
6262

63-
if (atomic_cas_ptr(&cached, NULL, name) != name)
63+
if (atomic_cas_ptr(&cached, NULL, name) != NULL)
6464
free(name);
6565

6666
return cached;

0 commit comments

Comments
 (0)