diff --git a/compat/arc4_lock.c b/compat/arc4_lock.c index 0c45ad01b..a78f75232 100644 --- a/compat/arc4_lock.c +++ b/compat/arc4_lock.c @@ -33,6 +33,9 @@ */ #include "config.h" #define LOCKRET(func) func +#ifdef ENABLE_LOCK_CHECKS +#undef ENABLE_LOCK_CHECKS +#endif #include "util/locks.h" void _ARC4_LOCK(void); @@ -46,6 +49,10 @@ void _ARC4_LOCK(void) void _ARC4_UNLOCK(void) { } + +void _ARC4_LOCK_DESTROY(void) +{ +} #else /* !THREADS_DISABLED */ static lock_quick_type arc4lock; @@ -64,4 +71,12 @@ void _ARC4_UNLOCK(void) { lock_quick_unlock(&arc4lock); } + +void _ARC4_LOCK_DESTROY(void) +{ + if(arc4lockinit) { + arc4lockinit = 0; + lock_quick_destroy(&arc4lock); + } +} #endif /* THREADS_DISABLED */ diff --git a/config.h.in b/config.h.in index 90038a88f..47aa147cb 100644 --- a/config.h.in +++ b/config.h.in @@ -1150,6 +1150,7 @@ uint32_t arc4random(void); void arc4random_buf(void* buf, size_t n); void _ARC4_LOCK(void); void _ARC4_UNLOCK(void); +void _ARC4_LOCK_DESTROY(void); #endif #ifndef HAVE_ARC4RANDOM_UNIFORM uint32_t arc4random_uniform(uint32_t upper_bound); diff --git a/configure.ac b/configure.ac index 822eed520..e3e222f89 100644 --- a/configure.ac +++ b/configure.ac @@ -1661,6 +1661,7 @@ uint32_t arc4random(void); void arc4random_buf(void* buf, size_t n); void _ARC4_LOCK(void); void _ARC4_UNLOCK(void); +void _ARC4_LOCK_DESTROY(void); #endif #ifndef HAVE_ARC4RANDOM_UNIFORM uint32_t arc4random_uniform(uint32_t upper_bound); diff --git a/daemon/daemon.c b/daemon/daemon.c index 13aba723a..f68bd981b 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -778,6 +778,9 @@ daemon_delete(struct daemon* daemon) # if defined(HAVE_SSL) && defined(OPENSSL_THREADS) && !defined(THREADS_DISABLED) ub_openssl_lock_delete(); # endif +#ifndef HAVE_ARC4RANDOM + _ARC4_LOCK_DESTROY(); +#endif #elif defined(HAVE_NSS) NSS_Shutdown(); #endif /* HAVE_SSL or HAVE_NSS */ diff --git a/daemon/unbound.c b/daemon/unbound.c index 10ab082e2..827246f0c 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -744,5 +744,10 @@ main(int argc, char* argv[]) run_daemon(cfgfile, cmdline_verbose, debug_mode, log_ident_default, need_pidfile); log_init(NULL, 0, NULL); /* close logfile */ +#ifndef unbound_testbound + if(log_get_lock()) { + lock_quick_destroy((lock_quick_type*)log_get_lock()); + } +#endif return 0; } diff --git a/doc/Changelog b/doc/Changelog index 3af4ff2fd..227aca428 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +2 February 2018: Wouter + - Fix unfreed locks in log and arc4random at exit of unbound. + 1 February 2018: Wouter - fix unaligned structure making a false positive in checklock unitialised memory. diff --git a/services/authzone.c b/services/authzone.c index f2baafb31..99b83c5f1 100644 --- a/services/authzone.c +++ b/services/authzone.c @@ -4276,6 +4276,8 @@ check_xfer_packet(sldns_buffer* pkt, struct auth_xfer* xfr, return 0; } /* check ID */ + log_info("id wire %x, want %x", (int)LDNS_ID_WIRE(wire), + (int)xfr->task_transfer->id); if(LDNS_ID_WIRE(wire) != xfr->task_transfer->id) { verbose(VERB_ALGO, "xfr to %s failed, packet wrong ID", xfr->task_transfer->master->host); diff --git a/testcode/testbound.c b/testcode/testbound.c index 5ec51ab3d..c9880cdd3 100644 --- a/testcode/testbound.c +++ b/testcode/testbound.c @@ -456,7 +456,10 @@ main(int argc, char* argv[]) for(c=1; c