Add:Core:Better support for debugging memory leaks
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 23 Jun 2010 13:06:57 +0000 (13:06 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 23 Jun 2010 13:06:57 +0000 (13:06 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3386 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/debug.c
navit/navit/debug.h

index fc6511c..c877451 100644 (file)
@@ -306,6 +306,16 @@ debug_malloc0(const char *where, int line, const char *func, int size)
        return ret;
 }
 
+void *
+debug_realloc(const char *where, int line, const char *func, void *ptr, int size)
+{
+       void *ret=debug_malloc(where, line, func, size);
+       if (ret && ptr)
+               memcpy(ret, ptr, size);
+       debug_free(where, line, func, ptr);
+       return ret;
+}
+
 char *
 debug_strdup(const char *where, int line, const char *func, const char *ptr)
 { 
index 6b41a7a..7a041c9 100644 (file)
@@ -38,6 +38,9 @@ extern int debug_level;
 #undef g_new0
 #define g_new(type, size) (type *)debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
 #define g_new0(type, size) (type *)debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
+#define g_malloc(size) debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
+#define g_malloc0(size) debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
+#define g_realloc(ptr,size) debug_realloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr,(size))
 #define g_free(ptr) debug_free(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
 #define g_strdup(ptr) debug_strdup(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
 #define g_strdup_printf(fmt...) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,g_strdup_printf(fmt))