diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-06-23 14:09:05 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-06-23 14:09:05 +0000 |
commit | a08b01264e8172846311f8c301c26da8a2c49a58 (patch) | |
tree | 15b5e663f3a5d4da059930f36cc59ac9a994e14c /navit/debug.c | |
parent | a1d989b5eaf8edaa9f9f936e929e122b4f7bcf9c (diff) | |
download | navit-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.c | 8 |
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); } |