changeset 30886:05057aa86c03

Fix thread safety issue in mreq_private: last_alloc was accessed from multiple threads without being under a mutex.
author sesse
date Wed, 17 Mar 2010 23:42:11 +0000
parents c634d15b475f
children f1e0aa08e3ee
files loader/win32.c
diffstat 1 files changed, 3 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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 */
     }