about summary refs log tree commit diff
path: root/malloc/malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r--malloc/malloc.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index a369001520..4cbce0455b 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2741,8 +2741,19 @@ static void do_check_malloc_state(mstate av)
   for (i = 0; i < NFASTBINS; ++i) {
     p = av->fastbins[i];
 
+    /* The following test can only be performed for the main arena.
+       While mallopt calls malloc_consolidate to get rid of all fast
+       bins (especially those larger than the new maximum) this does
+       only happen for the main arena.  Trying to do this for any
+       other arena would mean those arenas have to be locked and
+       malloc_consolidate be called for them.  This is excessive.  And
+       even if this is acceptable to somebody it still cannot solve
+       the problem completely since if the arena is locked a
+       concurrent malloc call might create a new arena which then
+       could use the newly invalid fast bins.  */
+
     /* all bins past max_fast are empty */
-    if (i > max_fast_bin)
+    if (av == &main_arena && i > max_fast_bin)
       assert(p == 0);
 
     while (p != 0) {
@@ -4097,7 +4108,6 @@ _int_malloc(mstate av, size_t bytes)
   for(;;) {
 
     int iters = 0;
-    bool any_larger = false;
     while ( (victim = unsorted_chunks(av)->bk) != unsorted_chunks(av)) {
       bck = victim->bk;
       if (__builtin_expect (victim->size <= 2 * SIZE_SZ, 0)
@@ -4194,8 +4204,6 @@ _int_malloc(mstate av, size_t bytes)
       fwd->bk = victim;
       bck->fd = victim;
 
-      if (size >= nb + MINSIZE)
-	any_larger = true;
 #define MAX_ITERS	10000
       if (++iters >= MAX_ITERS)
 	break;
@@ -4684,7 +4692,15 @@ static void malloc_consolidate(av) mstate av;
       reused anyway.
     */
 
+#if 0
+    /* It is wrong to limit the fast bins to search using get_max_fast
+       because, except for the main arena, all the others might have
+       blocks in the high fast bins.  It's not worth it anyway, just
+       search all bins all the time.  */
     maxfb = &(av->fastbins[fastbin_index(get_max_fast ())]);
+#else
+    maxfb = &(av->fastbins[NFASTBINS - 1]);
+#endif
     fb = &(av->fastbins[0]);
     do {
       if ( (p = *fb) != 0) {