]> git.ipfire.org Git - thirdparty/glibc.git/commit
malloc: Fix tcache leak after thread destruction [BZ #22111]
authorCarlos O'Donell <carlos@systemhalted.org>
Thu, 28 Sep 2017 17:05:18 +0000 (11:05 -0600)
committerCarlos O'Donell <carlos@systemhalted.org>
Fri, 6 Oct 2017 17:35:30 +0000 (10:35 -0700)
commit6e1ea21501eac981204c3cc8212d45998f74983c
treef6d73cb866f75b6d409727c5faa94a1634c41d94
parentdd3a7239fddff81ac31373d69978d7aa1902c65f
malloc: Fix tcache leak after thread destruction [BZ #22111]

The malloc tcache added in 2.26 will leak all of the elements remaining
in the cache and the cache structure itself when a thread exits. The
defect is that we do not set tcache_shutting_down early enough, and the
thread simply recreates the tcache and places the elements back onto a
new tcache which is subsequently lost as the thread exits (unfreed
memory). The fix is relatively simple, move the setting of
tcache_shutting_down earlier in tcache_thread_freeres. We add a test
case which uses mallinfo and some heuristics to look for unaccounted for
memory usage between the start and end of a thread start/join loop. It
is very reliable at detecting that there is a leak given the number of
iterations.  Without the fix the test will consume 122MiB of leaked
memory.

(cherry picked from commit 1e26d35193efbb29239c710a4c46a64708643320)
ChangeLog
malloc/Makefile
malloc/malloc.c
malloc/tst-malloc-tcache-leak.c [new file with mode: 0644]