From af2bddc242ae963c89e2f06e5a2587479ceced99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= <ondrej@isc.org>
Date: Wed, 23 Feb 2022 22:04:05 +0100
Subject: [PATCH] Properly free up enqueued netievents in nm_destroy()

When the isc_netmgr is being destroyed, the normal and priority queues
should be dequeued and netievents properly freed.  This wasn't the case.

(cherry picked from commit 88418c33729804cc86a9492e3e30f1123f56ddcd)
Conflict: isc_mem_put to isc_mempool_put
Reference: https://gitlab.isc.org/isc-projects/bind9/-/commit/af2bddc242ae963c89e2f06e5a2587479ceced99
---
 lib/isc/netmgr/netmgr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c
index ff5fd0f..6c24d41 100644
--- a/lib/isc/netmgr/netmgr.c
+++ b/lib/isc/netmgr/netmgr.c
@@ -418,14 +418,14 @@ nm_destroy(isc_nm_t **mgr0) {
 
 		/* Empty the async event queues */
 		while ((ievent = DEQUEUE_PRIORITY_NETIEVENT(worker)) != NULL) {
-			isc_mempool_put(mgr->evpool, ievent);
+			isc__nm_put_netievent(mgr, ievent);
 		}
 
 		INSIST(DEQUEUE_PRIVILEGED_NETIEVENT(worker) == NULL);
 		INSIST(DEQUEUE_TASK_NETIEVENT(worker) == NULL);
 
-		while ((ievent = DEQUEUE_PRIORITY_NETIEVENT(worker)) != NULL) {
-			isc_mempool_put(mgr->evpool, ievent);
+		while ((ievent = DEQUEUE_NORMAL_NETIEVENT(worker)) != NULL) {
+			isc__nm_put_netievent(mgr, ievent);
 		}
 		isc_condition_destroy(&worker->cond_prio);
 		isc_mutex_destroy(&worker->lock);
-- 
2.27.0

