This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] malloc: Fix missing accounting of top chunk in malloc_info [BZ #24026]
- From: Florian Weimer <fweimer at redhat dot com>
- To: libc-alpha at sourceware dot org
- Cc: Niklas Hambüchen <mail at nh2 dot me>
- Date: Thu, 01 Aug 2019 14:12:40 +0200
- Subject: [PATCH] malloc: Fix missing accounting of top chunk in malloc_info [BZ #24026]
Author: Niklas Hambüchen <mail@nh2.me>
Fixes `<total type="rest" size="..."> incorrectly showing as 0 most
of the time.
The rest value being wrong is significant because to compute the
actual amount of memory handed out via malloc, the user must subtract
it from <system type="current" size="...">. That result being wrong
makes investigating memory fragmentation issues like
https://bugzilla.redhat.com/show_bug.cgi?id=843478 close to
impossible.
[Patch from Bugzilla. Reformatted for GNU style.]
2019-08-01 Niklas Hambüchen <mail@nh2.me>
[BZ #24026]
* malloc/malloc.c (__malloc_info): Account for top chunk.
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 00ce48cf58..1083cd3ef2 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -5406,6 +5406,10 @@ __malloc_info (int options, FILE *fp)
__libc_lock_lock (ar_ptr->mutex);
+ /* Account for top chunk. */
+ avail = chunksize (ar_ptr->top);
+ nblocks = 1; /* Top always exists. */
+
for (size_t i = 0; i < NFASTBINS; ++i)
{
mchunkptr p = fastbin (ar_ptr, i);