Blame SOURCES/glibc-rh789238.patch

b40826
diff -rup a/malloc/malloc.c b/malloc/malloc.c
b40826
--- a/malloc/malloc.c	2012-02-13 21:46:11.678847531 -0700
b40826
+++ b/malloc/malloc.c	2012-02-13 22:43:14.788431976 -0700
b40826
@@ -3669,8 +3669,9 @@ public_mALLOc(size_t bytes)
b40826
     } else {
b40826
 #if USE_ARENAS
b40826
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b40826
-      ar_ptr = arena_get2(ar_ptr->next ? ar_ptr : 0, bytes);
b40826
-      (void)mutex_unlock(&main_arena.mutex);
b40826
+      mstate prev = ar_ptr->next ? ar_ptr : 0;
b40826
+      (void)mutex_unlock(&ar_ptr->mutex);
b40826
+      ar_ptr = arena_get2(prev, bytes);
b40826
       if(ar_ptr) {
b40826
 	victim = _int_malloc(ar_ptr, bytes);
b40826
 	(void)mutex_unlock(&ar_ptr->mutex);
b40826
@@ -3929,10 +3930,10 @@ public_vALLOc(size_t bytes)
b40826
   if(!ar_ptr)
b40826
     return 0;
b40826
   p = _int_valloc(ar_ptr, bytes);
b40826
-  (void)mutex_unlock(&ar_ptr->mutex);
b40826
   if(!p) {
b40826
     /* Maybe the failure is due to running out of mmapped areas. */
b40826
     if(ar_ptr != &main_arena) {
b40826
+      (void)mutex_unlock(&ar_ptr->mutex);
b40826
       ar_ptr = &main_arena;
b40826
       (void)mutex_lock(&ar_ptr->mutex);
b40826
       p = _int_memalign(ar_ptr, pagesz, bytes);
b40826
@@ -3940,14 +3941,17 @@ public_vALLOc(size_t bytes)
b40826
     } else {
b40826
 #if USE_ARENAS
b40826
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b40826
-      ar_ptr = arena_get2(ar_ptr->next ? ar_ptr : 0, bytes);
b40826
+      mstate prev = ar_ptr->next ? ar_ptr : 0;
b40826
+      (void)mutex_unlock(&ar_ptr->mutex);
b40826
+      ar_ptr = arena_get2(prev, bytes);
b40826
       if(ar_ptr) {
b40826
 	p = _int_memalign(ar_ptr, pagesz, bytes);
b40826
 	(void)mutex_unlock(&ar_ptr->mutex);
b40826
       }
b40826
 #endif
b40826
     }
b40826
-  }
b40826
+  } else
b40826
+    (void)mutex_unlock(&ar_ptr->mutex);
b40826
   assert(!p || chunk_is_mmapped(mem2chunk(p)) ||
b40826
 	 ar_ptr == arena_for_chunk(mem2chunk(p)));
b40826
 
b40826
@@ -3975,10 +3979,10 @@ public_pVALLOc(size_t bytes)
b40826
 
b40826
   arena_get(ar_ptr, bytes + 2*pagesz + MINSIZE);
b40826
   p = _int_pvalloc(ar_ptr, bytes);
b40826
-  (void)mutex_unlock(&ar_ptr->mutex);
b40826
   if(!p) {
b40826
     /* Maybe the failure is due to running out of mmapped areas. */
b40826
     if(ar_ptr != &main_arena) {
b40826
+      (void)mutex_unlock(&ar_ptr->mutex);
b40826
       ar_ptr = &main_arena;
b40826
       (void)mutex_lock(&ar_ptr->mutex);
b40826
       p = _int_memalign(ar_ptr, pagesz, rounded_bytes);
b40826
@@ -3986,15 +3990,17 @@ public_pVALLOc(size_t bytes)
b40826
     } else {
b40826
 #if USE_ARENAS
b40826
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b40826
-      ar_ptr = arena_get2(ar_ptr->next ? ar_ptr : 0,
b40826
-			  bytes + 2*pagesz + MINSIZE);
b40826
+      mstate prev = ar_ptr->next ? ar_ptr : 0;
b40826
+      (void)mutex_unlock(&ar_ptr->mutex);
b40826
+      ar_ptr = arena_get2(prev, bytes + 2*pagesz + MINSIZE);
b40826
       if(ar_ptr) {
b40826
 	p = _int_memalign(ar_ptr, pagesz, rounded_bytes);
b40826
 	(void)mutex_unlock(&ar_ptr->mutex);
b40826
       }
b40826
 #endif
b40826
     }
b40826
-  }
b40826
+  } else
b40826
+    (void)mutex_unlock(&ar_ptr->mutex);
b40826
   assert(!p || chunk_is_mmapped(mem2chunk(p)) ||
b40826
 	 ar_ptr == arena_for_chunk(mem2chunk(p)));
b40826
 
b40826
@@ -4064,8 +4070,6 @@ public_cALLOc(size_t n, size_t elem_size
b40826
 #endif
b40826
   mem = _int_malloc(av, sz);
b40826
 
b40826
-  /* Only clearing follows, so we can unlock early. */
b40826
-  (void)mutex_unlock(&av->mutex);
b40826
 
b40826
   assert(!mem || chunk_is_mmapped(mem2chunk(mem)) ||
b40826
 	 av == arena_for_chunk(mem2chunk(mem)));
b40826
@@ -4073,15 +4077,16 @@ public_cALLOc(size_t n, size_t elem_size
b40826
   if (mem == 0) {
b40826
     /* Maybe the failure is due to running out of mmapped areas. */
b40826
     if(av != &main_arena) {
b40826
+      (void)mutex_unlock(&av->mutex);
b40826
       (void)mutex_lock(&main_arena.mutex);
b40826
       mem = _int_malloc(&main_arena, sz);
b40826
       (void)mutex_unlock(&main_arena.mutex);
b40826
     } else {
b40826
 #if USE_ARENAS
b40826
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b40826
-      (void)mutex_lock(&main_arena.mutex);
b40826
-      av = arena_get2(av->next ? av : 0, sz);
b40826
-      (void)mutex_unlock(&main_arena.mutex);
b40826
+      mstate prev = av->next ? av : 0;
b40826
+      (void)mutex_unlock(&av->mutex);
b40826
+      av = arena_get2(prev, sz);
b40826
       if(av) {
b40826
 	mem = _int_malloc(av, sz);
b40826
 	(void)mutex_unlock(&av->mutex);
b40826
@@ -4089,7 +4094,8 @@ public_cALLOc(size_t n, size_t elem_size
b40826
 #endif
b40826
     }
b40826
     if (mem == 0) return 0;
b40826
-  }
b40826
+  } else
b40826
+    (void)mutex_unlock(&av->mutex);
b40826
   p = mem2chunk(mem);
b40826
 
b40826
   /* Two optional cases in which clearing not necessary */