]> 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@sury.org>
Wed, 8 Dec 2021 16:58:53 +0000 (17:58 +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).

lib/isc/netmgr/netmgr.c

index 13168683e11b20d97d4ad977a1c340f09c0e850d..51045521a1d22a03fda01fdbc7e2dcead0d2da3a 100644 (file)
@@ -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);