[v2,1/2] malloc: malloc_stats print all heaps except heaps of main_arena
diff mbox series

Message ID 1572074043-28091-1-git-send-email-liusirui@huawei.com
State New
Headers show
Series
  • [v2,1/2] malloc: malloc_stats print all heaps except heaps of main_arena
Related show

Commit Message

Liusirui Oct. 26, 2019, 7:14 a.m. UTC
An arena may have several heaps, and only the last heap contains top chunk.
malloc_stats only print the heap which contains top chunk. Now the function
prints all heaps of an arena.

---
 malloc/malloc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 5d3e82a..351e95f 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4965,6 +4965,7 @@  __malloc_stats (void)
 {
   int i;
   mstate ar_ptr;
+  heap_info *heap_ptr;
   unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
 
   if (__malloc_initialized < 0)
@@ -4984,7 +4985,13 @@  __malloc_stats (void)
       fprintf (stderr, "in use bytes     = %10u\n", (unsigned int) mi.uordblks);
 #if MALLOC_DEBUG > 1
       if (i > 0)
-        dump_heap (heap_for_ptr (top (ar_ptr)));
+      {
+        for (heap_ptr = heap_for_ptr (top (ar_ptr)); heap_ptr->ar_ptr != (mstate) (heap_ptr + 1); heap_ptr = heap_ptr->prev)
+        {
+          dump_heap (heap_ptr);
+        }
+	dump_heap (heap_ptr);
+      }
 #endif
       system_b += mi.arena;
       in_use_b += mi.uordblks;