Skip to content

Commit 2357e16

Browse files
committed
ZOOKEEPER-4810: Fix buf data race at format_endpoint_info()
format_endpoint_info() is widely called in the IO thread. And the some ZOOAPIs will call this method too: zoo_cycle_next_server() and zoo_get_current_server(). These APIs return the same static buffer read/write by IO thread causes data race.
1 parent 7074448 commit 2357e16

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

zookeeper-client/zookeeper-client-c/src/zookeeper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5111,11 +5111,11 @@ int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
51115111

51125112
static const char* format_endpoint_info(const struct sockaddr_storage* ep)
51135113
{
5114-
static char buf[134] = { 0 };
5114+
static __thread char buf[134] = { 0 };
51155115
char addrstr[INET6_ADDRSTRLEN] = { 0 };
51165116
const char *fmtstring;
51175117
void *inaddr;
5118-
char is_inet6 = 0; // poor man's boolean
5118+
char is_inet6 = 0; // poor man's boolean
51195119
#ifdef _WIN32
51205120
char * addrstring;
51215121
#endif

0 commit comments

Comments
 (0)