]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Fix missing accounting of top chunk in malloc_info [BZ #24026]
authorNiklas Hambüchen <mail@nh2.me>
Thu, 8 Aug 2019 20:02:27 +0000 (22:02 +0200)
committerArjun Shankar <ashankar@redhat.com>
Wed, 30 Oct 2019 18:35:19 +0000 (19:35 +0100)
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.

(cherry picked from commit b6d2c4475d5abc05dd009575b90556bdd3c78ad0)

ChangeLog
malloc/malloc.c

index 7b8a6fd2204147ac4659d83bd18feff50a2abc16..831b33892809042528b63ac715aa801705bf2ba8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-08-08  Niklas Hambüchen  <mail@nh2.me>
+           Carlos O'Donell  <carlos@redhat.com>
+
+       [BZ #24026]
+       * malloc/malloc.c (__malloc_info): Account for top chunk.
+
 2019-08-01  Florian Weimer  <fweimer@redhat.com>
 
        [BZ #24867]
index 06e18026f1bd023edb8e6c698fec0373b54ea629..e460b92782ebabb074202300996655a2b673a86d 100644 (file)
@@ -5438,6 +5438,12 @@ __malloc_info (int options, FILE *fp)
 
       __libc_lock_lock (ar_ptr->mutex);
 
+      /* Account for top chunk.  The top-most available chunk is
+        treated specially and is never in any bin. See "initial_top"
+        comments.  */
+      avail = chunksize (ar_ptr->top);
+      nblocks = 1;  /* Top always exists.  */
+
       for (size_t i = 0; i < NFASTBINS; ++i)
        {
          mchunkptr p = fastbin (ar_ptr, i);