This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Fix malloc_info statistic.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Fri, 1 Nov 2013 11:16:45 +0100
- Subject: [PATCH] Fix malloc_info statistic.
- Authentication-results: sourceware.org; auth=none
Hi, malloc_info could currently produce outputs like:
... snip
<size from="32785" to="32785" total="32785" count="1"/>
<size from="2512305" to="2512305" total="2512305" count="1"/>
<unsorted from="8993" to="8386112020140800621"
total="8316306148830692230" count="7526394837682317685"/>
</sizes>
Bogus numbers in unsorted field are caused by that when we
compute count we do not initialize sizes[NFASTBINS].count to zero.
A computation of these duplicates computation for rest of bins that is
just below. Handling first bin by this case fixes initialization issues.
OK to commit?
* malloc/malloc (malloc_info): Do not handle first bin as
special case.
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 29796fe..29a4e20 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -5049,23 +5049,11 @@ malloc_info (int options, FILE *fp)
sizes[i].total = sizes[i].count * sizes[i].to;
}
- mbinptr bin = bin_at (ar_ptr, 1);
- struct malloc_chunk *r = bin->fd;
- if (r != NULL)
- {
- while (r != bin)
- {
- ++sizes[NFASTBINS].count;
- sizes[NFASTBINS].total += r->size;
- sizes[NFASTBINS].from = MIN (sizes[NFASTBINS].from, r->size);
- sizes[NFASTBINS].to = MAX (sizes[NFASTBINS].to, r->size);
- r = r->fd;
- }
- nblocks += sizes[NFASTBINS].count;
- avail += sizes[NFASTBINS].total;
- }
- for (size_t i = 2; i < NBINS; ++i)
+ mbinptr bin;
+ struct malloc_chunk *r;
+
+ for (size_t i = 1; i < NBINS; ++i)
{
bin = bin_at (ar_ptr, i);
r = bin->fd;