]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Better method to ensure correct lifetime of query context
authorNick Porter <nick@portercomputing.co.uk>
Thu, 4 May 2023 12:50:22 +0000 (13:50 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 4 May 2023 14:25:21 +0000 (15:25 +0100)
Only cancelled trunk requests require the query context to last beyond
the stack frame they were allocated in.

src/lib/ldap/base.c
src/lib/ldap/referral.c

index 74e084f93f17dc883867a798844c2b691242737b..294989f1094d805c7647f051ff983c1edbe18bbe 100644 (file)
@@ -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:
index a5d56a988999d5fe77441955bde79eba610495b3..47e90d4f76f08a947cb8817f6bf3535f64f3d82a 100644 (file)
@@ -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: