This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2] malloc: Fix tcache leak on thread destruction [BZ #22111]
- From: DJ Delorie <dj at redhat dot com>
- To: "Carlos O'Donell" <carlos at redhat dot com>
- Cc: fweimer at redhat dot com, libc-alpha at sourceware dot org
- Date: Mon, 02 Oct 2017 21:36:22 -0400
- Subject: Re: [PATCH v2] malloc: Fix tcache leak on thread destruction [BZ #22111]
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dj at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6D2EE4A6E6
Carlos O'Donell <carlos@systemhalted.org> writes:
> diff --git a/malloc/tst-malloc-tcache-leak.c b/malloc/tst-malloc-tcache-leak.c
> +void *
> +worker (void *data)
> +{
> + /* Allocate an arbitrary amount of memory that is known to fit into
> + the thread local cache (tcache). If we have at least 64 bins
> + (default e.g. TCACHE_MAX_BINS) we should be able to allocate 32
> + bytes and force malloc to fill the tcache. We have the allocated
> + memory escape back to the parent to be freed to avoid any compiler
> + optimizations. */
> + return (void *) xmalloc (32);
> +}
This would be slightly more future-proof if it did an alloc/free/alloc
cycle, in case in the future malloc doesn't init the tcache "just
because". The free would force the init, since the chunk would be
stored in the tcache.
Actually, a malloc/free might be a better test, since it tests that the
free'd chunks in the tcache are freed as well as the tcache
infrastructure itself. Or maybe as a second test.
Also, some protection against user-environment tunables disabling the
tcache might be appropriate, although that would only stop false
positives.