Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix malloc_info without prioor allocations.
  • Loading branch information
Ulrich Drepper committed Jan 14, 2010
1 parent 52e2ea9 commit 346bc35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,5 +1,9 @@
2010-01-14 Ulrich Drepper <drepper@redhat.com>

[BZ #11126]
* malloc/malloc.c (malloc_info): Initialize malloc if not already
done. Handle empty bin lists.

* posix/unistd.h: Change getpagesize and getdtablesize declaration
visibility some more.

Expand Down
41 changes: 24 additions & 17 deletions malloc/malloc.c
Expand Up @@ -6369,16 +6369,19 @@ malloc_info (int options, FILE *fp)

mbinptr bin = bin_at (ar_ptr, 1);
struct malloc_chunk *r = bin->fd;
while (r != bin)
if (r != NULL)
{
++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;
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;
}
nblocks += sizes[NFASTBINS].count;
avail += sizes[NFASTBINS].total;

for (size_t i = 2; i < NBINS; ++i)
{
Expand All @@ -6388,17 +6391,18 @@ malloc_info (int options, FILE *fp)
sizes[NFASTBINS - 1 + i].to = sizes[NFASTBINS - 1 + i].total
= sizes[NFASTBINS - 1 + i].count = 0;

while (r != bin)
{
++sizes[NFASTBINS - 1 + i].count;
sizes[NFASTBINS - 1 + i].total += r->size;
sizes[NFASTBINS - 1 + i].from = MIN (sizes[NFASTBINS - 1 + i].from,
if (r != NULL)
while (r != bin)
{
++sizes[NFASTBINS - 1 + i].count;
sizes[NFASTBINS - 1 + i].total += r->size;
sizes[NFASTBINS - 1 + i].from
= MIN (sizes[NFASTBINS - 1 + i].from, r->size);
sizes[NFASTBINS - 1 + i].to = MAX (sizes[NFASTBINS - 1 + i].to,
r->size);
sizes[NFASTBINS - 1 + i].to = MAX (sizes[NFASTBINS - 1 + i].to,
r->size);

r = r->fd;
}
r = r->fd;
}

if (sizes[NFASTBINS - 1 + i].count == 0)
sizes[NFASTBINS - 1 + i].from = 0;
Expand Down Expand Up @@ -6460,6 +6464,9 @@ malloc_info (int options, FILE *fp)
fputs ("</heap>\n", fp);
}

if(__malloc_initialized < 0)
ptmalloc_init ();

fputs ("<malloc version=\"1\">\n", fp);

/* Iterate over all arenas currently in use. */
Expand Down

0 comments on commit 346bc35

Please sign in to comment.