Added the debugging_(malloc|calloc|free) functions to help track memory

usage. There are also now defines for safe(malloc|calloc|free) which allow
for debugging code to be enabled or not.
This commit is contained in:
Robert James Kaes committed 2001-09-08 18:55:58 +00:00
1 parent b8a694e7a3
commit 4923dd22a7
2 files changed
+51 -5

No files matched your search

+19 -1
View File
@@ -1,4 +1,4 @@
/* $Id: utils.h,v 1.6 2001-08-30 16:52:56 rjkaes Exp $
/* $Id: utils.h,v 1.7 2001-09-08 18:55:58 rjkaes Exp $
*
* See 'utils.h' for a detailed description.
*
@@ -34,4 +34,22 @@ extern size_t strlcat(char *dst, const char *src, size_t size);
extern size_t strlcpy(char *dst, const char *src, size_t size);
#endif /* HAVE_STRLCPY */
/*
* The following is to allow for better memory checking.
*/
#ifndef NDEBUG
extern void *debugging_calloc(size_t nmemb, size_t size, const char *file, unsigned long line);
extern void *debugging_malloc(size_t size, const char *file, unsigned long line);
extern void debugging_free(void *ptr, const char *file, unsigned long line);
# define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
# define safefree(x) debugging_free(x, __FILE__, __LINE__)
#else
# define safecalloc(x, y) calloc(x, y)
# define safemalloc(x) malloc(x)
# define safefree(x) free(x)
#endif
#endif