From 7a13c923afdec8765f8c33e93ae5eee7dfc4dc11 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 11 Feb 2016 17:12:44 +0100 Subject: lib: clean/restore memory debugging functions This adapts the dump-at-exit handler and removes the old leftover code. (Note the text in log_memtype_stderr was actually incorrect as the only caller in bgpd cleans up configuration before calling it, i.e. any remaining allocations are missing-cleanup bugs.) Signed-off-by: David Lamparter Acked-by: Vincent JARDIN Acked-by: Donald Sharp --- lib/memory.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/memory.c') diff --git a/lib/memory.c b/lib/memory.c index 562b0f589a..38e424da7d 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -112,3 +112,38 @@ qmem_walk (qmem_walk_fn *func, void *arg) } return 0; } + +struct exit_dump_args +{ + const char *prefix; + int error; +}; + +static int +qmem_exit_walker (void *arg, struct memgroup *mg, struct memtype *mt) +{ + struct exit_dump_args *eda = arg; + + if (!mt) + { + fprintf (stderr, "%s: showing active allocations in memory group %s\n", + eda->prefix, mg->name); + } + else if (mt->n_alloc) + { + char size[32]; + eda->error++; + snprintf (size, sizeof (size), "%10zu", mt->size); + fprintf (stderr, "%s: %-30s: %6zu * %s\n", + eda->prefix, mt->name, mt->n_alloc, + mt->size == SIZE_VAR ? "(variably sized)" : size); + } + return 0; +} + +void +log_memstats_stderr (const char *prefix) +{ + struct exit_dump_args eda = { .prefix = prefix, .error = 0 }; + qmem_walk (qmem_exit_walker, &eda); +} -- cgit v1.2.3