]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Avoid premature fallback to mmap [BZ #20284]
authorFlorian Weimer <fweimer@redhat.com>
Tue, 21 Jun 2016 19:29:21 +0000 (21:29 +0200)
committerMike Frysinger <vapier@gentoo.org>
Sat, 12 Nov 2016 05:44:38 +0000 (00:44 -0500)
Before this change, the while loop in reused_arena which avoids
returning a corrupt arena would never execute its body if the selected
arena were not corrupt.  As a result, result == begin after the loop,
and the function returns NULL, triggering fallback to mmap.

(cherry picked from commit a3b473373ee43a292f5ec68a7fda6b9cfb26a9b0)
(cherry picked from commit a69d26143b80cb1927481509279577c57bc22ba4)

malloc/arena.c

index 0e5cc0f54d8eadd992cd3ffb4f9321681d054aa5..232b6a29600dd8c68f83faa04509a729c0091ddc 100644 (file)
@@ -795,14 +795,12 @@ reused_arena (mstate avoid_arena)
     {
       result = result->next;
       if (result == begin)
-       break;
+       /* We looped around the arena list.  We could not find any
+          arena that was either not corrupted or not the one we
+          wanted to avoid.  */
+       return NULL;
     }
 
-  /* We could not find any arena that was either not corrupted or not the one
-     we wanted to avoid.  */
-  if (result == begin || result == avoid_arena)
-    return NULL;
-
   /* No arena available without contention.  Wait for the next in line.  */
   LIBC_PROBE (memory_arena_reuse_wait, 3, &result->mutex, result, avoid_arena);
   (void) mutex_lock (&result->mutex);