ce426f
commit a3b473373ee43a292f5ec68a7fda6b9cfb26a9b0
ce426f
Author: Florian Weimer <fweimer@redhat.com>
ce426f
Date:   Tue Jun 21 21:29:21 2016 +0200
ce426f
ce426f
    malloc: Avoid premature fallback to mmap [BZ #20284]
ce426f
    
ce426f
    Before this change, the while loop in reused_arena which avoids
ce426f
    returning a corrupt arena would never execute its body if the selected
ce426f
    arena were not corrupt.  As a result, result == begin after the loop,
ce426f
    and the function returns NULL, triggering fallback to mmap.
ce426f
ce426f
Index: glibc-2.17-c758a686/malloc/arena.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/malloc/arena.c
ce426f
+++ glibc-2.17-c758a686/malloc/arena.c
ce426f
@@ -907,14 +907,12 @@ reused_arena (mstate avoid_arena)
ce426f
     {
ce426f
       result = result->next;
ce426f
       if (result == begin)
ce426f
-	break;
ce426f
+	/* We looped around the arena list.  We could not find any
ce426f
+	   arena that was either not corrupted or not the one we
ce426f
+	   wanted to avoid.  */
ce426f
+	return NULL;
ce426f
     }
ce426f
 
ce426f
-  /* We could not find any arena that was either not corrupted or not the one
ce426f
-     we wanted to avoid.  */
ce426f
-  if (result == begin || result == avoid_arena)
ce426f
-    return NULL;
ce426f
-
ce426f
   /* No arena available without contention.  Wait for the next in line.  */
ce426f
   LIBC_PROBE (memory_arena_reuse_wait, 3, &result->mutex, result, avoid_arena);
ce426f
   (void)mutex_lock(&result->mutex);