]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Don't leave freed thread trunks in the tree of ldap connections
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 3 Nov 2021 18:08:04 +0000 (14:08 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 3 Nov 2021 18:08:04 +0000 (14:08 -0400)
src/lib/ldap/connection.c
src/modules/rlm_ldap/rlm_ldap.c

index a647d3b393596a5c0050a0e2f6abf752a928546d..69a5fd6af35647b4a27f9e639108077b44f3ed52 100644 (file)
@@ -491,7 +491,7 @@ static void _ldap_trunk_idle_timeout(fr_event_list_t *el, UNUSED fr_time_t now,
        fr_ldap_thread_trunk_t  *ttrunk = talloc_get_type_abort(uctx, fr_ldap_thread_trunk_t);
 
        if (ttrunk->trunk->req_alloc == 0) {
-               DEBUG2("Removing idle LDAP trunk to %s", ttrunk->uri);
+               DEBUG2("Removing idle LDAP trunk to \"%s\"", ttrunk->uri);
                talloc_free(ttrunk->trunk);
                talloc_free(ttrunk);
        } else {
@@ -928,6 +928,13 @@ static void ldap_trunk_request_demux(fr_trunk_connection_t *tconn, fr_connection
        } while (1);
 }
 
+static int _thread_ldap_trunk_free(fr_ldap_thread_trunk_t *ttrunk)
+{
+       if (ttrunk->t && fr_rb_node_inline_in_tree(&ttrunk->node)) fr_rb_remove(ttrunk->t->trunks, ttrunk);
+
+       return 0;
+}
+
 /** Find a thread specific LDAP connection for a specific URI / bind DN
  *
  * If no existing connection exists for that combination then create a new one
@@ -957,6 +964,7 @@ fr_ldap_thread_trunk_t *fr_thread_ldap_trunk_get(fr_ldap_thread_t *thread, char
         */
        ROPTIONAL(RDEBUG2, DEBUG2, "No existing connection found - creating new one");
        found = talloc_zero(thread, fr_ldap_thread_trunk_t);
+       talloc_set_destructor(found, _thread_ldap_trunk_free);
 
        /*
         *      Buld config for this connection - start with module settings and
index e85d2bd65e75d4ee77788bfa198b3f61b314fe29..45c2794e5b34ab2c7cf8f3ce53747f2a21cd6bc2 100644 (file)
@@ -1817,7 +1817,7 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread)
             ttrunk;
             ttrunk = fr_rb_iter_next_preorder(&iter)) {
                talloc_free(ttrunk->trunk);
-            }
+       }
        talloc_free(this_thread->trunks);
        return 0;
 }