From 2534fa520329bce2a91aa39b3564b68e0e6867a4 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 26 Mar 2004 21:09:44 +0000 Subject: [PATCH] Add string display to mem leak dump. --- lib/mm/dbg_malloc.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/mm/dbg_malloc.c b/lib/mm/dbg_malloc.c index b8b0c6c6f..995a268ee 100644 --- a/lib/mm/dbg_malloc.c +++ b/lib/mm/dbg_malloc.c @@ -159,13 +159,26 @@ int dump_memory(void) { unsigned long tot = 0; struct memblock *mb; + char str[32]; + size_t c; + if (_head) log_very_verbose("You have a memory leak:"); for (mb = _head; mb; mb = mb->next) { + for (c = 0; c < sizeof(str) - 1; c++) { + if (c >= mb->length) + str[c] = ' '; + else if (*(char *)(mb->magic + c) < ' ') + str[c] = '?'; + else + str[c] = *(char *)(mb->magic + c); + } + str[sizeof(str) - 1] = '\0'; + print_log(_LOG_INFO, mb->file, mb->line, - "block %d at %p, size %" PRIdPTR, - mb->id, mb->magic, mb->length); + "block %d at %p, size %" PRIdPTR "\t [%s]", + mb->id, mb->magic, mb->length, str); tot += mb->length; }