From 7c750db5806acdafac899bff91cc593ce9a27624 Mon Sep 17 00:00:00 2001 From: hniksic Date: Thu, 23 Nov 2000 13:44:56 -0800 Subject: [PATCH] [svn] More memory debug tweaks. Published in . --- src/ChangeLog | 9 +++++++++ src/utils.c | 16 +++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8f30490c..12ddf711 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2000-11-23 Hrvoje Niksic + + * utils.c (xrealloc_debug): Do the unregister/register thing only + if the pointer has actually changed. + (xmalloc_real): Declare `static' in DEBUG_MALLOC builds. + (xfree_real): Ditto. + (xrealloc_real): Ditto. + (xstrdup_real): Ditto. + 2000-11-22 Hrvoje Niksic * ftp.c (getftp): ftp_getaddress() returns a malloc'ed copy of the diff --git a/src/utils.c b/src/utils.c index ecf944c3..b59125aa 100644 --- a/src/utils.c +++ b/src/utils.c @@ -119,7 +119,13 @@ memfatal (const char *what) Each of the *_debug function does its magic and calls the real one. */ -void * +#ifdef DEBUG_MALLOC +# define STATIC_IF_DEBUG static +#else +# define STATIC_IF_DEBUG +#endif + +STATIC_IF_DEBUG void * xmalloc_real (size_t size) { void *ptr = malloc (size); @@ -128,13 +134,13 @@ xmalloc_real (size_t size) return ptr; } -void +STATIC_IF_DEBUG void xfree_real (void *ptr) { free (ptr); } -void * +STATIC_IF_DEBUG void * xrealloc_real (void *ptr, size_t newsize) { void *newptr; @@ -151,7 +157,7 @@ xrealloc_real (void *ptr, size_t newsize) return newptr; } -char * +STATIC_IF_DEBUG char * xstrdup_real (const char *s) { char *copy; @@ -285,7 +291,7 @@ xrealloc_debug (void *ptr, size_t newsize, const char *source_file, int source_l ++malloc_count; register_ptr (newptr, source_file, source_line); } - else + else if (newptr != ptr) { unregister_ptr (ptr); register_ptr (newptr, source_file, source_line);