From: Ondřej Surý Date: Mon, 24 Nov 2025 09:49:18 +0000 (+0100) Subject: Split qctx_destroy() into qctx_deinit() and qctx_destroy() X-Git-Tag: v9.21.16~28^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e94a31a666ed5c9d5cf1b06843ecf7ac002f05c9;p=thirdparty%2Fbind9.git Split qctx_destroy() into qctx_deinit() and qctx_destroy() 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. --- diff --git a/lib/ns/include/ns/query.h b/lib/ns/include/ns/query.h index c336c80dcae..0b7196dd4dd 100644 --- a/lib/ns/include/ns/query.h +++ b/lib/ns/include/ns/query.h @@ -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 */ }; diff --git a/lib/ns/query.c b/lib/ns/query.c index 3e7e37d56e5..43448d332bb 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -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; }