From 57d0fabaddf0e7ac297a046b084df8fb22d54d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 6 Dec 2021 11:10:17 +0100 Subject: [PATCH 1/2] Stop leaking mutex in nmworker and cond in nm socket On FreeBSD, the pthread primitives are not solely allocated on stack, but part of the object lives on the heap. Missing pthread_*_destroy causes the heap memory to grow and in case of fast lived object it's possible to run out-of-memory. Properly destroy the leaking mutex (worker->lock) and the leaking condition (sock->cond). --- lib/isc/netmgr/netmgr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 13168683e1..51045521a1 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -379,6 +379,7 @@ nm_destroy(isc_nm_t **mgr0) { isc_mem_put(mgr->mctx, ievent, sizeof(*ievent)); } isc_condition_destroy(&worker->cond_prio); + isc_mutex_destroy(&worker->lock); r = uv_loop_close(&worker->loop); INSIST(r == 0); @@ -1271,8 +1272,9 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) { sock->ah_size * sizeof(sock->ah_frees[0])); isc_mem_put(sock->mgr->mctx, sock->ah_handles, sock->ah_size * sizeof(sock->ah_handles[0])); - isc_mutex_destroy(&sock->lock); isc_condition_destroy(&sock->scond); + isc_condition_destroy(&sock->cond); + isc_mutex_destroy(&sock->lock); #if HAVE_LIBNGHTTP2 isc__nm_tls_cleanup_data(sock); isc__nm_http_cleanup_data(sock); From dff5888d9b00e932a1aa66eaca1ace76b9671cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 8 Dec 2021 11:24:47 +0100 Subject: [PATCH 2/2] Add CHANGES and release not for [GL #3051] --- CHANGES | 4 ++++ doc/notes/notes-current.rst | 3 +++ 2 files changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index 3451a38c85..8d26051d1f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +5776. [bug] Add a missing isc_condition_destroy() for nmsocket + condition variable and add missing isc_mutex_destroy() + for nmworker lock. [GL #3051] + 5775. [bug] Added a timer in the resolver to kill fetches that have deadlocked as a result of dependency loops with the ADB or the validator. This condition is diff --git a/doc/notes/notes-current.rst b/doc/notes/notes-current.rst index 3e6b31f3d6..9480b5fae8 100644 --- a/doc/notes/notes-current.rst +++ b/doc/notes/notes-current.rst @@ -79,3 +79,6 @@ Bug Fixes - The resolver could hang on shutdown due to dispatch resources not being cleaned up when a TCP connection was reset. This has been fixed. :gl:`#3026` + +- On FreeBSD, a TCP connection would leak a small amount of heap memory leading + to out-of-memory problem in a long run. This has been fixed. :gl:`#3051`