]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Split qctx_destroy() into qctx_deinit() and qctx_destroy()
authorOndřej Surý <ondrej@isc.org>
Mon, 24 Nov 2025 09:49:18 +0000 (10:49 +0100)
committerOndřej Surý <ondrej@isc.org>
Thu, 27 Nov 2025 09:37:58 +0000 (10:37 +0100)
The qctx_destroy() only needs to be called on allocated memory and
qctx_deinit() needs to be called always.  Also remove .allocated member
from the query_ctx_t structure.

lib/ns/include/ns/query.h
lib/ns/query.c

index c336c80dcae0f9f9cd6aa54fe74daa885fb9b4a2..0b7196dd4dd4137544d4eae929b9138be67d5070 100644 (file)
@@ -231,8 +231,6 @@ struct query_ctx {
 
        void *zhooks; /* zone hook table */
 
-       bool allocated; /* qctx needs to be freed when destroying */
-
        isc_result_t result; /* query result */
        int          line;   /* line to report error */
 };
index 3e7e37d56e5d3686df6a8ca6d9d05cc1bdbe523c..43448d332bb294413966ed5ebc6bfef73f7ec8e0 100644 (file)
@@ -441,7 +441,10 @@ static void
 qctx_freedata(query_ctx_t *qctx);
 
 static void
-qctx_destroy(query_ctx_t *qctx);
+qctx_destroy(query_ctx_t **qctx);
+
+static void
+qctx_deinit(query_ctx_t *qctx);
 
 static void
 query_setup(ns_client_t *client, dns_rdatatype_t qtype);
@@ -2764,7 +2767,7 @@ stale_refresh_aftermath(ns_client_t *client, isc_result_t result) {
 
        cleanup:
                qctx_freedata(&qctx);
-               qctx_destroy(&qctx);
+               qctx_deinit(&qctx);
        }
 }
 
@@ -5199,14 +5202,18 @@ qctx_freedata(query_ctx_t *qctx) {
 }
 
 static void
-qctx_destroy(query_ctx_t *qctx) {
+qctx_destroy(query_ctx_t **qctxp) {
+       query_ctx_t *qctx = *qctxp;
+       *qctxp = NULL;
+
+       isc_mem_put(qctx->client->manager->mctx, qctx, sizeof(*qctx));
+}
+
+static void
+qctx_deinit(query_ctx_t *qctx) {
        if (qctx->view) {
                dns_view_detach(&qctx->view);
        }
-
-       if (qctx->allocated) {
-               isc_mem_put(qctx->client->manager->mctx, qctx, sizeof(*qctx));
-       }
 }
 
 /*
@@ -5259,8 +5266,6 @@ qctx_save(query_ctx_t *src, query_ctx_t **targetp) {
        target->view = NULL;
        dns_view_attach(src->view, &target->view);
 
-       target->allocated = true;
-
        *targetp = target;
 }
 
@@ -5328,7 +5333,7 @@ query_setup(ns_client_t *client, dns_rdatatype_t qtype) {
        (void)ns__query_start(&qctx);
 
 cleanup:
-       qctx_destroy(&qctx);
+       qctx_deinit(&qctx);
 }
 
 static bool
@@ -5817,7 +5822,8 @@ async_restart(void *arg) {
 
        qctx_clean(qctx);
        qctx_freedata(qctx);
-       qctx_destroy(qctx);
+       qctx_deinit(qctx);
+       qctx_destroy(&qctx);
        isc_nmhandle_detach(&handle);
 }
 
@@ -6228,7 +6234,7 @@ fetch_callback(void *arg) {
                }
        }
 
-       qctx_destroy(&qctx);
+       qctx_deinit(&qctx);
        dns_resolver_destroyfetch(&fetch);
 }
 
@@ -6736,7 +6742,8 @@ query_hookresume(void *arg) {
 
        isc_mem_put(hctx->mctx, rev, sizeof(*rev));
        hctx->destroy(&hctx);
-       qctx_destroy(qctx);
+       qctx_deinit(qctx);
+       qctx_destroy(&qctx);
 }
 
 isc_result_t
@@ -6801,7 +6808,8 @@ cleanup:
        if (saved_qctx != NULL) {
                qctx_clean(saved_qctx);
                qctx_freedata(saved_qctx);
-               qctx_destroy(saved_qctx);
+               qctx_deinit(saved_qctx);
+               qctx_destroy(&saved_qctx);
        }
        return result;
 }