Changeset: 8f7959c60646 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8f7959c60646 Modified Files: tools/merovingian/daemon/controlrunner.c Branch: Nov2019 Log Message:
Fixed race condition. If connections are made fast enough and the first started thread hasn't read it's argument yet before the next connection is made, it's data pointer was overwritten. We now allocate new memory for each connection so that each thread is guaranteed to get the correct data. diffs (35 lines): diff --git a/tools/merovingian/daemon/controlrunner.c b/tools/merovingian/daemon/controlrunner.c --- a/tools/merovingian/daemon/controlrunner.c +++ b/tools/merovingian/daemon/controlrunner.c @@ -1001,6 +1001,7 @@ handle_client(void *p) { int msgsock = * (int *) p; + free(p); ctl_handle_client("(local)", msgsock, NULL, NULL); shutdown(msgsock, SHUT_RDWR); closesocket(msgsock); @@ -1016,8 +1017,13 @@ controlRunner(void *d) struct timeval tv; int msgsock; pthread_t tid; + int *p; do { + if ((p = malloc(sizeof(int))) == NULL) { + Mfprintf(_mero_ctlerr, "malloc failed"); + break; + } FD_ZERO(&fds); FD_SET(usock, &fds); @@ -1050,7 +1056,8 @@ controlRunner(void *d) (void) fcntl(msgsock, F_SETFD, FD_CLOEXEC); #endif - if (pthread_create(&tid, NULL, handle_client, &msgsock) != 0) + *p = msgsock; + if (pthread_create(&tid, NULL, handle_client, p) != 0) closesocket(msgsock); else pthread_detach(tid); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list