From: Nick Porter Date: Thu, 4 May 2023 12:50:22 +0000 (+0100) Subject: Better method to ensure correct lifetime of query context X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b453b7eba03911bc1a1b6ab723b163d78bcffa1c;p=thirdparty%2Ffreeradius-server.git Better method to ensure correct lifetime of query context Only cancelled trunk requests require the query context to last beyond the stack frame they were allocated in. --- diff --git a/src/lib/ldap/base.c b/src/lib/ldap/base.c index 74e084f93f1..294989f1094 100644 --- a/src/lib/ldap/base.c +++ b/src/lib/ldap/base.c @@ -621,6 +621,12 @@ static void ldap_trunk_query_cancel(UNUSED request_t *request, UNUSED fr_signal_ */ if (!query->treq) return; + /* + * The query needs to be parented by the treq so that it still + * exists when the cancel_mux callback is run. + */ + talloc_steal(query->treq, query); + fr_trunk_request_signal_cancel(query->treq); /* @@ -629,7 +635,6 @@ static void ldap_trunk_query_cancel(UNUSED request_t *request, UNUSED fr_signal_ * the trunk code. */ query->treq = NULL; - } #define SET_LDAP_CTRLS(_dest, _src) \ @@ -699,10 +704,6 @@ unlang_action_t fr_ldap_trunk_search(rlm_rcode_t *p_result, switch (fr_trunk_request_enqueue(&query->treq, ttrunk->trunk, request, query, NULL)) { case FR_TRUNK_ENQUEUE_OK: case FR_TRUNK_ENQUEUE_IN_BACKLOG: - /* - * Ensure the query ctx will last until the trunk request frees its children - */ - talloc_reference(query->treq, query); break; default: @@ -776,10 +777,6 @@ unlang_action_t fr_ldap_trunk_modify(rlm_rcode_t *p_result, switch (fr_trunk_request_enqueue(&query->treq, ttrunk->trunk, request, query, NULL)) { case FR_TRUNK_ENQUEUE_OK: case FR_TRUNK_ENQUEUE_IN_BACKLOG: - /* - * Ensure the query ctx will last until the trunk request frees its children - */ - talloc_reference(query->treq, query); break; default: @@ -872,10 +869,6 @@ unlang_action_t fr_ldap_trunk_extended(rlm_rcode_t *p_result, switch (fr_trunk_request_enqueue(&query->treq, ttrunk->trunk, request, query, NULL)) { case FR_TRUNK_ENQUEUE_OK: case FR_TRUNK_ENQUEUE_IN_BACKLOG: - /* - * Ensure the query ctx will last until the trunk request frees its children - */ - talloc_reference(query->treq, query); break; default: diff --git a/src/lib/ldap/referral.c b/src/lib/ldap/referral.c index a5d56a98899..47e90d4f76f 100644 --- a/src/lib/ldap/referral.c +++ b/src/lib/ldap/referral.c @@ -82,7 +82,6 @@ static void _ldap_referral_send(UNUSED fr_trunk_t *trunk, UNUSED fr_trunk_state_ switch (fr_trunk_request_enqueue(&query->treq, referral->ttrunk->trunk, request, query, NULL)) { case FR_TRUNK_ENQUEUE_OK: case FR_TRUNK_ENQUEUE_IN_BACKLOG: - talloc_reference(query->treq, query); break; default: @@ -238,7 +237,6 @@ int fr_ldap_referral_follow(fr_ldap_thread_t *t, request_t *request, fr_ldap_que switch (fr_trunk_request_enqueue(&query->treq, ttrunk->trunk, request, query, NULL)) { case FR_TRUNK_ENQUEUE_OK: case FR_TRUNK_ENQUEUE_IN_BACKLOG: - talloc_reference(query->treq, query); break; default: @@ -330,7 +328,6 @@ int fr_ldap_referral_next(fr_ldap_thread_t *t, request_t *request, fr_ldap_query switch(fr_trunk_request_enqueue(&query->treq, ttrunk->trunk, request, query, NULL)) { case FR_TRUNK_ENQUEUE_OK: case FR_TRUNK_ENQUEUE_IN_BACKLOG: - talloc_reference(query->treq, query); break; default: