added memoryDebug.c memory info to cmd_meminfo
authorpk910 <philipp@zoelle1.de>
Mon, 30 Jan 2012 16:49:18 +0000 (17:49 +0100)
committerpk910 <philipp@zoelle1.de>
Mon, 30 Jan 2012 16:49:18 +0000 (17:49 +0100)
src/memoryDebug.c

index 442e618e1dfe0dbbf144d387bc82bcf947db1151..e870f4ba4854f2253a1b424b41c7b71a91dc0f81 100644 (file)
@@ -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) {