diff -up glibc-2.12-2-gc4ccff1/malloc/arena.c.orig glibc-2.12-2-gc4ccff1/malloc/arena.c --- glibc-2.12-2-gc4ccff1/malloc/arena.c.orig 2015-10-09 23:55:19.638596777 +0800 +++ glibc-2.12-2-gc4ccff1/malloc/arena.c 2015-10-09 23:56:27.420659953 +0800 @@ -1148,8 +1148,27 @@ arena_thread_freeres (void) if (a != NULL) { (void)mutex_lock(&list_lock); - a->next_free = free_list; - free_list = a; + /* Do not make free_list a cyclic one element list. */ + if (a != free_list) + { + if (free_list != NULL) + { + mstate b = free_list; + /* Check if not already in free_list. */ + while (b->next_free != NULL) + { + /* "a" can be at most once in free_list. */ + if (b->next_free == a) + { + b->next_free = a->next_free; + break; + } + b = b->next_free; + } + } + a->next_free = free_list; + free_list = a; + } (void)mutex_unlock(&list_lock); } }