configure option for memory allocation debugging.

git-svn-id: file:///svn/unbound/trunk@598 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-09-05 13:47:23 +00:00
parent 7b76e85956
commit 5f9e30aacb
3 changed files with 15 additions and 23 deletions

View file

@ -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);

View file

@ -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

View file

@ -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