From 01583c031e83360b5c6f349a8d6082c96698f07f Mon Sep 17 00:00:00 2001 From: pk910 Date: Mon, 30 Jan 2012 17:49:18 +0100 Subject: [PATCH] added memoryDebug.c memory info to cmd_meminfo --- src/memoryDebug.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/memoryDebug.c b/src/memoryDebug.c index 442e618..e870f4b 100644 --- a/src/memoryDebug.c +++ b/src/memoryDebug.c @@ -44,6 +44,8 @@ static pthread_mutex_t synchronized; static struct MemoryLeak *ptr_start = NULL; +static unsigned int own_allocated_memleaks = 0; + static void add_mem_info(void * mem_ref, unsigned int size, const char *file, unsigned int line); static void remove_mem_info(void * mem_ref); @@ -81,7 +83,8 @@ void xfree(void *mem_ref) { static void add_mem_info(void *mem_ref, unsigned int size, const char *file, unsigned int line) { SYNCHRONIZE(synchronized); - struct MemoryLeak *mem_leak_info = malloc (sizeof(*mem_leak_info)); + struct MemoryLeak *mem_leak_info = malloc(sizeof(*mem_leak_info)); + own_allocated_memleaks++; mem_leak_info->mem_info.address = mem_ref; mem_leak_info->mem_info.size = size; strcpy(mem_leak_info->mem_info.file_name, file); @@ -101,6 +104,7 @@ static void remove_mem_info(void *mem_ref) { prev->next = next; else ptr_start = next; + own_allocated_memleaks--; free(leak_info); break; } else @@ -163,8 +167,14 @@ struct memoryInfoFiles *getMemoryInfoFiles() { element->allocations += 1; element->allocated += leak_info->mem_info.size; } + element = malloc(sizeof(*element)); + element->filename = strdup(__FILE__); + element->allocations = own_allocated_memleaks; + element->allocated = own_allocated_memleaks * sizeof(struct MemoryLeak); + element->next = list; + list = element; DESYNCHRONIZE(synchronized); - return element; + return list; } void freeMemoryInfoFiles(struct memoryInfoFiles *files) { @@ -197,8 +207,16 @@ struct memoryInfoLines *getMemoryInfoLines(const char *filename) { } element->allocations++; } + if(!stricmp(filename, __FILE__)) { + element = malloc(sizeof(*element)); + element->line = 0; + element->allocations = own_allocated_memleaks; + element->allocate = sizeof(struct MemoryLeak); + element->next = list; + list = element; + } DESYNCHRONIZE(synchronized); - return element; + return list; } void freeMemoryInfoLines(struct memoryInfoLines *lines) { -- 2.20.1