Add built-in debug malloc wrapper.
[srvx.git] / src / common.h
index 952b1de056e85cc90241ac82eae7f3fd03a0b6e9..a8458a37db958e7e0ffdeff166589334a55b961d 100644 (file)
@@ -64,25 +64,40 @@ extern struct tm *localtime_r(const time_t *clock, struct tm *res);
 #endif
 
 #if defined(WITH_MALLOC_DMALLOC)
-#define DMALLOC_FUNC_CHECK 1
-#include <string.h>
-#include <dmalloc.h>
+# define DMALLOC_FUNC_CHECK 1
+# include <string.h>
+# include <dmalloc.h>
 #elif defined(WITH_MALLOC_MPATROL)
-#include <string.h>
-#include <mpatrol.h>
+# include <string.h>
+# include <mpatrol.h>
 #elif defined(WITH_MALLOC_BOEHM_GC)
-#if !defined(NDEBUG)
-#define GC_DEBUG 1
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <gc/gc.h>
-#define malloc(n) GC_MALLOC(n)
-#define calloc(m,n) GC_MALLOC((m)*(n))
-#define realloc(p,n) GC_REALLOC((p),(n))
-#define free(p) GC_FREE(p)
-#undef  HAVE_STRDUP
-#undef strdup
+# if !defined(NDEBUG)
+#  define GC_DEBUG 1
+# endif
+# include <stdlib.h>
+# include <string.h>
+# include <gc/gc.h>
+# define malloc(n) GC_MALLOC(n)
+# define calloc(m,n) GC_MALLOC((m)*(n))
+# define realloc(p,n) GC_REALLOC((p),(n))
+# define free(p) GC_FREE(p)
+# undef  HAVE_STRDUP
+# undef strdup
+#elif defined(WITH_MALLOC_SRVX)
+# undef malloc
+# define malloc(n) srvx_malloc(__FILE__, __LINE__, (n))
+# undef calloc
+# define calloc(m,n) srvx_malloc(__FILE__, __LINE__, (m)*(n))
+# undef realloc
+# define realloc(p,n) srvx_realloc(__FILE__, __LINE__, (p), (n))
+# undef free
+# define free(p) srvx_free(__FILE__, __LINE__, (p))
+# undef strdup
+# define strdup(s) srvx_strdup(__FILE__, __LINE__, (s))
+extern void *srvx_malloc(const char *, unsigned int, size_t);
+extern void *srvx_realloc(const char *, unsigned int, void *, size_t);
+extern char *srvx_strdup(const char *, unsigned int, const char *);
+extern void srvx_free(const char *, unsigned int, void *);
 #endif
 
 extern time_t now;