@@ -, +, @@ When a thread leaves, arena_thread_freeres is called, the malloc A common problem can be described as: free_list->next_free = free_list; When a program has several short lived threads, and most commonly --- malloc/arena.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/malloc/arena.c +++ a/malloc/arena.c @@ -934,9 +934,18 @@ arena_thread_freeres (void) if (a != NULL) { + mstate b; (void) mutex_lock (&list_lock); - a->next_free = free_list; - free_list = a; + /* Insert "a" last in free_list. */ + if (free_list != NULL) + { + for (b = free_list; b->next_free != NULL; b = b->next_free) + ; + b->next_free = a; + } + else + free_list = a; + a->next_free = NULL; (void) mutex_unlock (&list_lock); } } --