From: Nick Porter Date: Fri, 28 Apr 2023 18:38:18 +0000 (+0100) Subject: Parent the directory discovery query from a trunk request X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55c2c126129015b522dbcfbc6002ec6806a2e835;p=thirdparty%2Ffreeradius-server.git Parent the directory discovery query from a trunk request So that the query is cleared up when the request is completed - there is no further use for the query after demux processing. --- diff --git a/src/lib/ldap/connection.c b/src/lib/ldap/connection.c index 671e1dffd9d..b7bbe80b0cd 100644 --- a/src/lib/ldap/connection.c +++ b/src/lib/ldap/connection.c @@ -740,6 +740,7 @@ static void ldap_trunk_request_demux(fr_event_list_t *el, fr_trunk_connection_t fr_ldap_query_t find = { .msgid = -1 }, *query = NULL; request_t *request; bool really_no_result = false; + fr_trunk_request_t *treq; /* * Reset the idle timeout event @@ -911,8 +912,14 @@ static void ldap_trunk_request_demux(fr_event_list_t *el, fr_trunk_connection_t * Mark the trunk request as complete and set the request as runnable */ if (query->treq->request) unlang_interpret_mark_runnable(query->treq->request); - fr_trunk_request_signal_complete(query->treq); + + /* + * If the query is parented off just the treq, then it will be freed when + * the request is completed. If it has other parenting, then it will not. + */ + treq = query->treq; query->treq = NULL; + fr_trunk_request_signal_complete(treq); } while (1); } diff --git a/src/lib/ldap/directory.c b/src/lib/ldap/directory.c index 90a98f752a9..fa3bee5f361 100644 --- a/src/lib/ldap/directory.c +++ b/src/lib/ldap/directory.c @@ -254,14 +254,19 @@ int fr_ldap_trunk_directory_alloc_async(TALLOC_CTX *ctx, fr_ldap_thread_trunk_t { fr_ldap_query_t *query; static char const *attrs[] = LDAP_DIRECTORY_ATTRS; + fr_trunk_request_t *treq; ttrunk->directory = talloc_zero(ctx, fr_ldap_directory_t); if (!ttrunk->directory) return -1; ttrunk->directory->type = FR_LDAP_DIRECTORY_UNKNOWN; - query = fr_ldap_search_alloc(ctx, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, NULL, NULL); + treq = fr_trunk_request_alloc(ttrunk->trunk, NULL); + if (!treq) return -1; + + query = fr_ldap_search_alloc(treq, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, NULL, NULL); query->parser = ldap_trunk_directory_alloc_read; + query->treq = treq; fr_trunk_request_enqueue(&query->treq, ttrunk->trunk, NULL, query, ttrunk->directory);