From 5f9e30aacb9de2ff0c955ed1f18cc239c23b9b77 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 5 Sep 2007 13:47:23 +0000 Subject: [PATCH] configure option for memory allocation debugging. git-svn-id: file:///svn/unbound/trunk@598 be551aaa-1e26-0410-a405-d3ace91eadb9 --- configure.ac | 30 ++++++++---------------------- daemon/worker.c | 7 ++++++- doc/Changelog | 1 + 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index 16d89fe8b..f2db4bdaa 100644 --- a/configure.ac +++ b/configure.ac @@ -490,6 +490,14 @@ if test x_$enable_lock_checks = x_yes; then AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).]) fi +# set memory allocation checking if requested +AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks], + [ enable to check memory allocation, for debug purposes ]), + , ) +if test x_$enable_alloc_checks = x_yes; then + AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use]) +fi + # check to see if libraries are needed for these functions. AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, inet_pton) @@ -644,33 +652,11 @@ struct sockaddr_storage; #include "ldns/ldns.h" -/* use statistics for allocs and frees, for debug use */ -#define UNBOUND_ALLOC_STATS #ifdef UNBOUND_ALLOC_STATS -# ifdef malloc -# undef malloc /* keepoff autoheader */ -# endif -# ifdef realloc -# undef realloc /* keepoff autoheader */ -# endif -# ifdef calloc -# undef calloc /* keepoff autoheader */ -# endif -# ifdef free -# undef free /* keepoff autoheader */ -# endif - -#if 0 # define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__) # define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__) # define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__) # define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__) -#else -# define malloc unbound_stat_malloc -# define calloc unbound_stat_calloc -# define free unbound_stat_free -# define realloc unbound_stat_realloc -#endif void *unbound_stat_malloc(size_t size); void *unbound_stat_calloc(size_t nmemb, size_t size); void unbound_stat_free(void *ptr); diff --git a/daemon/worker.c b/daemon/worker.c index f16867420..6cd76b66b 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -70,6 +70,7 @@ /** Size of an UDP datagram */ #define NORMAL_UDP_SIZE 512 /* bytes */ +#ifdef UNBOUND_ALLOC_STATS /** measure memory leakage */ static void debug_memleak(size_t accounted, size_t heap, @@ -108,11 +109,14 @@ debug_total_mem(size_t calctotal) debug_memleak(calctotal, (size_t)total, unbound_mem_alloc, unbound_mem_freed); } +#endif /* UNBOUND_ALLOC_STATS */ /** Report on memory usage by this thread and global */ void -worker_mem_report(struct worker* worker, struct serviced_query* cur_serv) +worker_mem_report(struct worker* ATTR_UNUSED(worker), + struct serviced_query* ATTR_UNUSED(cur_serv)) { +#ifdef UNBOUND_ALLOC_STATS /* debug func in validator module */ size_t total, front, back, mesh, msg, rrset, infra, ac, superac; size_t me, iter, val; @@ -153,6 +157,7 @@ worker_mem_report(struct worker* worker, struct serviced_query* cur_serv) (unsigned)infra, (unsigned)iter, (unsigned)val, (unsigned)ac, (unsigned)superac, (unsigned)me); debug_total_mem(total); +#endif /* UNBOUND_ALLOC_STATS */ } void diff --git a/doc/Changelog b/doc/Changelog index fc75b59c6..3651af37d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -12,6 +12,7 @@ Also, for wildcard name NSECs, check they are not from the parent zone (for wildcarded zone cuts), and check absence of CNAME bit, for a nodata proof. + - configure option for memory allocation debugging. 4 September 2007: Wouter - fixup of Leakage warning when serviced queries processed multiple -- 2.47.2