From da245035dd488875b227f447f6882475731e26a9 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 10 Nov 2005 16:33:04 +0000 Subject: [PATCH] fix debug linking --- lib/libdevmapper.h | 18 +++++++++++------- lib/mm/dbg_malloc.c | 18 ++++-------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/libdevmapper.h b/lib/libdevmapper.h index 75e19f8..f8c1525 100644 --- a/lib/libdevmapper.h +++ b/lib/libdevmapper.h @@ -342,23 +342,26 @@ int dm_tree_node_add_target_area(struct dm_tree_node *node, * Memory management *******************/ -void *dm_malloc_aux(size_t s, const char *file, int line); -#define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__) - char *dm_strdup(const char *str); -#ifdef DEBUG_MEM - +void *dm_malloc_aux(size_t s, const char *file, int line); +void *dm_malloc_aux_debug(size_t s, const char *file, int line); void dm_free_aux(void *p); void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line); -int dm_dump_memory(void); -void dm_bounds_check(void); +int dm_dump_memory_debug(void); +void dm_bounds_check_debug(void); + +#ifdef DEBUG_MEM +# define dm_malloc(s) dm_malloc_aux_debug((s), __FILE__, __LINE__) # define dm_free(p) dm_free_aux(p) # define dm_realloc(p, s) dm_realloc_aux(p, s, __FILE__, __LINE__) +# define dm_dump_memory_debug() +# define dm_bounds_check_debug() #else +# define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__) # define dm_free(p) free(p) # define dm_realloc(p, s) realloc(p, s) # define dm_dump_memory() @@ -366,6 +369,7 @@ void dm_bounds_check(void); #endif + /* * The pool allocator is useful when you are going to allocate * lots of memory, use the memory for a bit, and then free the diff --git a/lib/mm/dbg_malloc.c b/lib/mm/dbg_malloc.c index 2e9ac94..6c87297 100644 --- a/lib/mm/dbg_malloc.c +++ b/lib/mm/dbg_malloc.c @@ -28,8 +28,6 @@ char *dm_strdup(const char *str) return ret; } -#ifdef DEBUG_MEM - struct memblock { struct memblock *prev, *next; /* All allocated blocks are linked */ size_t length; /* Size of the requested block */ @@ -51,7 +49,7 @@ static struct { static struct memblock *_head = 0; static struct memblock *_tail = 0; -void *dm_malloc_aux(size_t s, const char *file, int line) +void *dm_malloc_aux_debug(size_t s, const char *file, int line) { struct memblock *nb; size_t tsize = s + sizeof(*nb) + sizeof(unsigned long); @@ -72,9 +70,7 @@ void *dm_malloc_aux(size_t s, const char *file, int line) nb->file = file; nb->line = line; -#ifdef BOUNDS_CHECK dm_bounds_check(); -#endif /* setup fields */ nb->magic = nb + 1; @@ -125,9 +121,7 @@ void dm_free_aux(void *p) if (!p) return; -#ifdef BOUNDS_CHECK dm_bounds_check(); -#endif /* sanity check */ assert(mb->magic == p); @@ -171,7 +165,7 @@ void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line) void *r; struct memblock *mb = ((struct memblock *) p) - 1; - r = dm_malloc_aux(s, file, line); + r = dm_malloc_aux_debug(s, file, line); if (p) { memcpy(r, p, mb->length); @@ -181,7 +175,7 @@ void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line) return r; } -int dm_dump_memory(void) +int dm_dump_memory_debug(void) { unsigned long tot = 0; struct memblock *mb; @@ -216,7 +210,7 @@ int dm_dump_memory(void) return 1; } -void dm_bounds_check(void) +void dm_bounds_check_debug(void) { struct memblock *mb = _head; while (mb) { @@ -230,8 +224,6 @@ void dm_bounds_check(void) } } -#else - void *dm_malloc_aux(size_t s, const char *file, int line) { if (s > 50000000) { @@ -242,5 +234,3 @@ void *dm_malloc_aux(size_t s, const char *file, int line) return malloc(s); } - -#endif -- 2.43.5