]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Stop leaking mutex in nmworker and cond in nm socket
authorOndřej Surý <ondrej@sury.org>
Mon, 6 Dec 2021 10:10:17 +0000 (11:10 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 8 Dec 2021 17:19:37 +0000 (18:19 +0100)
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).

(cherry picked from commit 57d0fabaddf0e7ac297a046b084df8fb22d54d51)

lib/isc/netmgr/netmgr.c

index 54042a9123fa0936ca1b64a3a1c6d5a9c32721a3..e81ad4673e72231452855a5cfd8198e22ee0bba7 100644 (file)
@@ -425,6 +425,7 @@ nm_destroy(isc_nm_t **mgr0) {
                        isc_mempool_put(mgr->evpool, ievent);
                }
                isc_condition_destroy(&worker->cond_prio);
+               isc_mutex_destroy(&worker->lock);
 
                r = uv_loop_close(&worker->loop);
                INSIST(r == 0);
@@ -1267,8 +1268,9 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) {
 
        isc_mem_free(sock->mgr->mctx, sock->ah_frees);
        isc_mem_free(sock->mgr->mctx, sock->ah_handles);
-       isc_mutex_destroy(&sock->lock);
        isc_condition_destroy(&sock->scond);
+       isc_condition_destroy(&sock->cond);
+       isc_mutex_destroy(&sock->lock);
 #ifdef NETMGR_TRACE
        LOCK(&sock->mgr->lock);
        ISC_LIST_UNLINK(sock->mgr->active_sockets, sock, active_link);