diff options
author | peter <peter@FreeBSD.org> | 2002-07-20 04:18:20 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2002-07-20 04:18:20 +0000 |
commit | c7181950f3493ca9216d41ff1f5bf0e783f55f2e (patch) | |
tree | 95f9d7512ae7144422a04c5de32a3fa7f9db0f88 /lib/libstand/stand.h | |
parent | 7409589c7afc48621815fb92ece4a2ad2fe9cd75 (diff) | |
download | FreeBSD-src-c7181950f3493ca9216d41ff1f5bf0e783f55f2e.zip FreeBSD-src-c7181950f3493ca9216d41ff1f5bf0e783f55f2e.tar.gz |
Reimplement malloc/free debugging that includes the offending file:line
info. This turned out to be rather useful on ia64 for tracking down
malloc/free problems.
Detect duplicate free()'s - otherwise these show up as a guard1 failure
and it looks like corruption instead of something simple like a second
free() where there shouldn't be.
Deal with libz using libc headers and not seeing the malloc/free stuff that
we provide in libstand. Do similar nastiness to what is done for bzlib.
Tested on: i386, ia64 (compile, run)
Diffstat (limited to 'lib/libstand/stand.h')
-rw-r--r-- | lib/libstand/stand.h | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h index f3e0121..a062179 100644 --- a/lib/libstand/stand.h +++ b/lib/libstand/stand.h @@ -391,26 +391,19 @@ extern uint16_t ntohs(uint16_t); #define ntohs(x) __ntohs(x) #endif -#if 0 - -static inline void * -malloc_debug(size_t size, const char *file, int line) -{ - void *p; - printf("%s:%d malloc(%ld)", file, line, size); - p = malloc(size); - printf("=%p\n", p); - return p; -} - -static inline void -free_debug(void *p, const char *file, int line) -{ - printf("%s:%d free(%p)\n", file, line, p); - free(p); -} - -#define malloc(x) malloc_debug(x, __FILE__, __LINE__) -#define free(x) free_debug(x, __FILE__, __LINE__) - +void *Malloc(size_t, const char *, int); +void *Calloc(size_t, size_t, const char *, int); +void *Realloc(void *, size_t, const char *, int); +void Free(void *, const char *, int); + +#if 1 +#define malloc(x) Malloc(x, __FILE__, __LINE__) +#define calloc(x, y) Calloc(x, y, __FILE__, __LINE__) +#define free(x) Free(x, __FILE__, __LINE__) +#define realloc(x, y) Realloc(x, y, __FILE__, __LINE__) +#else +#define malloc(x) Malloc(x, NULL 0) +#define calloc(x, y) Calloc(x, y, NULL, 0) +#define free(x) Free(x, NULL, 0) +#define realloc(x, y) Realloc(x, y, NULL, 0) #endif |