diff --git a/malloc/malloc.c b/malloc/malloc.c index f8e7250..de6d7fa 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -4146,6 +4146,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) mchunkptr bck; /* misc temp for linking */ mchunkptr fwd; /* misc temp for linking */ + static int alternate; size = chunksize (p); /* Little security check which won't hurt performance: the @@ -4364,8 +4365,14 @@ _int_free (mstate av, mchunkptr p, int have_lock) if (av == &main_arena) { #ifndef MORECORE_CANNOT_TRIM if ((unsigned long)(chunksize(av->top)) >= - (unsigned long)(mp_.trim_threshold)) - systrim(mp_.top_pad, av); + (unsigned long)(mp_.trim_threshold)) { + if (alternate) { + systrim(mp_.top_pad, av); + alternate = 0; + } else { + alternate = 1; + } + } #endif } else { /* Always try heap_trim(), even if the top chunk is not