Blame SOURCES/glibc-rh726517.patch

b9ba6d
Index: glibc-2.12-2-gc4ccff1/malloc/arena.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/malloc/arena.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/malloc/arena.c
b9ba6d
@@ -870,7 +870,7 @@ heap_trim(heap, pad) heap_info *heap; si
b9ba6d
     heap = prev_heap;
b9ba6d
     if(!prev_inuse(p)) { /* consolidate backward */
b9ba6d
       p = prev_chunk(p);
b9ba6d
-      unlink(p, bck, fwd);
b9ba6d
+      unlink(ar_ptr, p, bck, fwd);
b9ba6d
     }
b9ba6d
     assert(((unsigned long)((char*)p + new_size) & (pagesz-1)) == 0);
b9ba6d
     assert( ((char*)p + new_size) == ((char*)heap + heap->size) );
b9ba6d
Index: glibc-2.12-2-gc4ccff1/malloc/hooks.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/malloc/hooks.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/malloc/hooks.c
b9ba6d
@@ -219,7 +219,9 @@ top_check()
b9ba6d
 	(char*)t + chunksize(t) == mp_.sbrk_base + main_arena.system_mem)))
b9ba6d
     return 0;
b9ba6d
 
b9ba6d
+  mutex_unlock(&main_arena);
b9ba6d
   malloc_printerr (check_action, "malloc: top chunk is corrupt", t);
b9ba6d
+  mutex_lock(&main_arena);
b9ba6d
 
b9ba6d
   /* Try to set up a new top chunk. */
b9ba6d
   brk = MORECORE(0);
b9ba6d
Index: glibc-2.12-2-gc4ccff1/malloc/malloc.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/malloc/malloc.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/malloc/malloc.c
b9ba6d
@@ -2109,12 +2109,14 @@ typedef struct malloc_chunk* mbinptr;
b9ba6d
 #define last(b)      ((b)->bk)
b9ba6d
 
b9ba6d
 /* Take a chunk off a bin list */
b9ba6d
-#define unlink(P, BK, FD) {                                            \
b9ba6d
+#define unlink(AV, P, BK, FD) {					       \
b9ba6d
   FD = P->fd;                                                          \
b9ba6d
   BK = P->bk;                                                          \
b9ba6d
-  if (__builtin_expect (FD->bk != P || BK->fd != P, 0))                \
b9ba6d
+  if (__builtin_expect (FD->bk != P || BK->fd != P, 0)) {	       \
b9ba6d
+    mutex_unlock(&(AV)->mutex);					       \
b9ba6d
     malloc_printerr (check_action, "corrupted double-linked list", P); \
b9ba6d
-  else {                                                               \
b9ba6d
+    mutex_lock(&(AV)->mutex);					       \
b9ba6d
+  } else {							       \
b9ba6d
     FD->bk = BK;                                                       \
b9ba6d
     BK->fd = FD;                                                       \
b9ba6d
     if (!in_smallbin_range (P->size)				       \
b9ba6d
@@ -3257,7 +3259,9 @@ static Void_t* sYSMALLOc(nb, av) INTERNA
b9ba6d
 
b9ba6d
     else if (contiguous(av) && old_size && brk < old_end) {
b9ba6d
       /* Oops!  Someone else killed our space..  Can't touch anything.  */
b9ba6d
+      mutex_unlock(&av->mutex);
b9ba6d
       malloc_printerr (3, "break adjusted to free malloc space", brk);
b9ba6d
+      mutex_lock(&av->mutex);
b9ba6d
     }
b9ba6d
 
b9ba6d
     /*
b9ba6d
@@ -4305,7 +4309,9 @@ _int_malloc(mstate av, size_t bytes)
b9ba6d
 	{
b9ba6d
 	  errstr = "malloc(): memory corruption (fast)";
b9ba6d
 	errout:
b9ba6d
+	  mutex_unlock(&av->mutex);
b9ba6d
 	  malloc_printerr (check_action, errstr, chunk2mem (victim));
b9ba6d
+	  mutex_lock(&av->mutex);
b9ba6d
 	  return NULL;
b9ba6d
 	}
b9ba6d
 #ifndef ATOMIC_FASTBINS
b9ba6d
@@ -4393,8 +4399,12 @@ _int_malloc(mstate av, size_t bytes)
b9ba6d
       bck = victim->bk;
b9ba6d
       if (__builtin_expect (victim->size <= 2 * SIZE_SZ, 0)
b9ba6d
 	  || __builtin_expect (victim->size > av->system_mem, 0))
b9ba6d
-	malloc_printerr (check_action, "malloc(): memory corruption",
b9ba6d
-			 chunk2mem (victim));
b9ba6d
+	{
b9ba6d
+	  void *p = chunk2mem(victim);
b9ba6d
+	  mutex_unlock(&av->mutex);
b9ba6d
+	  malloc_printerr (check_action, "malloc(): memory corruption", p);
b9ba6d
+	  mutex_lock(&av->mutex);
b9ba6d
+	}
b9ba6d
       size = chunksize(victim);
b9ba6d
 
b9ba6d
       /*
b9ba6d
@@ -4535,7 +4545,7 @@ _int_malloc(mstate av, size_t bytes)
b9ba6d
 	  victim = victim->fd;
b9ba6d
 
b9ba6d
 	remainder_size = size - nb;
b9ba6d
-	unlink(victim, bck, fwd);
b9ba6d
+	unlink(av, victim, bck, fwd);
b9ba6d
 
b9ba6d
 	/* Exhaust */
b9ba6d
 	if (remainder_size < MINSIZE)  {
b9ba6d
@@ -4633,7 +4643,7 @@ _int_malloc(mstate av, size_t bytes)
b9ba6d
 	remainder_size = size - nb;
b9ba6d
 
b9ba6d
 	/* unlink */
b9ba6d
-	unlink(victim, bck, fwd);
b9ba6d
+	unlink(av, victim, bck, fwd);
b9ba6d
 
b9ba6d
 	/* Exhaust */
b9ba6d
 	if (remainder_size < MINSIZE) {
b9ba6d
@@ -4789,10 +4799,14 @@ _int_free(mstate av, mchunkptr p)
b9ba6d
       errstr = "free(): invalid pointer";
b9ba6d
     errout:
b9ba6d
 #ifdef ATOMIC_FASTBINS
b9ba6d
-      if (! have_lock && locked)
b9ba6d
+      if (have_lock || locked)
b9ba6d
 	(void)mutex_unlock(&av->mutex);
b9ba6d
 #endif
b9ba6d
       malloc_printerr (check_action, errstr, chunk2mem(p));
b9ba6d
+#ifdef ATOMIC_FASTBINS
b9ba6d
+      if (have_lock)
b9ba6d
+	mutex_lock(&av->mutex);
b9ba6d
+#endif
b9ba6d
       return;
b9ba6d
     }
b9ba6d
   /* We know that each chunk is at least MINSIZE bytes in size.  */
b9ba6d
@@ -4961,7 +4975,7 @@ _int_free(mstate av, mchunkptr p)
b9ba6d
       prevsize = p->prev_size;
b9ba6d
       size += prevsize;
b9ba6d
       p = chunk_at_offset(p, -((long) prevsize));
b9ba6d
-      unlink(p, bck, fwd);
b9ba6d
+      unlink(av, p, bck, fwd);
b9ba6d
     }
b9ba6d
 
b9ba6d
     if (nextchunk != av->top) {
b9ba6d
@@ -4970,7 +4984,7 @@ _int_free(mstate av, mchunkptr p)
b9ba6d
 
b9ba6d
       /* consolidate forward */
b9ba6d
       if (!nextinuse) {
b9ba6d
-	unlink(nextchunk, bck, fwd);
b9ba6d
+	unlink(av, nextchunk, bck, fwd);
b9ba6d
 	size += nextsize;
b9ba6d
       } else
b9ba6d
 	clear_inuse_bit_at_offset(nextchunk, 0);
b9ba6d
@@ -5158,7 +5172,7 @@ static void malloc_consolidate(av) mstat
b9ba6d
 	    prevsize = p->prev_size;
b9ba6d
 	    size += prevsize;
b9ba6d
 	    p = chunk_at_offset(p, -((long) prevsize));
b9ba6d
-	    unlink(p, bck, fwd);
b9ba6d
+	    unlink(av, p, bck, fwd);
b9ba6d
 	  }
b9ba6d
 
b9ba6d
 	  if (nextchunk != av->top) {
b9ba6d
@@ -5166,7 +5180,7 @@ static void malloc_consolidate(av) mstat
b9ba6d
 
b9ba6d
 	    if (!nextinuse) {
b9ba6d
 	      size += nextsize;
b9ba6d
-	      unlink(nextchunk, bck, fwd);
b9ba6d
+	      unlink(av, nextchunk, bck, fwd);
b9ba6d
 	    } else
b9ba6d
 	      clear_inuse_bit_at_offset(nextchunk, 0);
b9ba6d
 
b9ba6d
@@ -5235,7 +5249,9 @@ _int_realloc(mstate av, mchunkptr oldp, 
b9ba6d
     {
b9ba6d
       errstr = "realloc(): invalid old size";
b9ba6d
     errout:
b9ba6d
+      mutex_unlock(&av->mutex);
b9ba6d
       malloc_printerr (check_action, errstr, chunk2mem(oldp));
b9ba6d
+      mutex_lock(&av->mutex);
b9ba6d
       return NULL;
b9ba6d
     }
b9ba6d
 
b9ba6d
@@ -5282,7 +5298,7 @@ _int_realloc(mstate av, mchunkptr oldp, 
b9ba6d
 	       (unsigned long)(newsize = oldsize + nextsize) >=
b9ba6d
 	       (unsigned long)(nb)) {
b9ba6d
 	newp = oldp;
b9ba6d
-	unlink(next, bck, fwd);
b9ba6d
+	unlink(av, next, bck, fwd);
b9ba6d
       }
b9ba6d
 
b9ba6d
       /* allocate, copy, free */