# HG changeset patch # User sesse # Date 1268869331 0 # Node ID 05057aa86c03268a4f5f59879df1924a8ea8bf32 # Parent c634d15b475f830feb1edf5a6036f4eef65e2058 Fix thread safety issue in mreq_private: last_alloc was accessed from multiple threads without being under a mutex. diff -r c634d15b475f -r 05057aa86c03 loader/win32.c --- a/loader/win32.c Wed Mar 17 23:38:26 2010 +0000 +++ b/loader/win32.c Wed Mar 17 23:42:11 2010 +0000 @@ -146,7 +146,7 @@ static unsigned int (*localcount)()=localcount_stub; static void (*longcount)(long long*)=longcount_stub; -static pthread_mutex_t memmut; +static pthread_mutex_t memmut = PTHREAD_MUTEX_INITIALIZER; static unsigned int localcount_stub(void) { @@ -366,14 +366,9 @@ if (to_zero) memset(header, 0, nsize); #ifdef GARBAGE - if (!last_alloc) + pthread_mutex_lock(&memmut); + if (last_alloc) { - pthread_mutex_init(&memmut, NULL); - pthread_mutex_lock(&memmut); - } - else - { - pthread_mutex_lock(&memmut); last_alloc->next = header; /* set next */ }