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