summaryrefslogtreecommitdiff
path: root/navit/debug.c
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-06-23 14:09:05 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-06-23 14:09:05 +0000
commita08b01264e8172846311f8c301c26da8a2c49a58 (patch)
tree15b5e663f3a5d4da059930f36cc59ac9a994e14c /navit/debug.c
parenta1d989b5eaf8edaa9f9f936e929e122b4f7bcf9c (diff)
downloadnavit-a08b01264e8172846311f8c301c26da8a2c49a58.tar.gz
Add:Core:Better support for debugging memory leaks
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3387 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/debug.c')
-rw-r--r--navit/debug.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/navit/debug.c b/navit/debug.c
index c87745100..158c4426d 100644
--- a/navit/debug.c
+++ b/navit/debug.c
@@ -246,7 +246,7 @@ struct malloc_tail {
int magic;
};
-int mallocs;
+int mallocs,malloc_size,malloc_size_m;
void
debug_dump_mallocs(void)
@@ -273,6 +273,11 @@ debug_malloc(const char *where, int line, const char *func, int size)
if (!size)
return NULL;
mallocs++;
+ malloc_size+=size;
+ if (malloc_size/(1024*1024) != malloc_size_m) {
+ malloc_size_m=malloc_size/(1024*1024);
+ dbg(0,"malloced %d kb\n",malloc_size/1024);
+ }
head=malloc(size+sizeof(*head)+sizeof(*tail));
head->magic=0xdeadbeef;
head->size=size;
@@ -347,6 +352,7 @@ debug_free(const char *where, int line, const char *func, void *ptr)
mallocs--;
head=(struct malloc_head *)((unsigned char *)ptr-sizeof(*head));
tail=(struct malloc_tail *)((unsigned char *)ptr+head->size);
+ malloc_size-=head->size;
if (head->magic != 0xdeadbeef || tail->magic != 0xdeadbef0) {
fprintf(stderr,"Invalid free from %s:%d %s\n",where,line,func);
}