From: Alan T. DeKok Date: Wed, 18 May 2022 00:17:51 +0000 (-0400) Subject: clean up internal requests if they have no parent X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f8b9bb3ad94687b378f5539a1010310a089bc80;p=thirdparty%2Ffreeradius-server.git clean up internal requests if they have no parent Specifically for trigger_exec(), which can be called with a real interpreter, but no parent for the "request" which is running the trigger. --- diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index a5de9fc2fcf..781c2394ac5 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -996,7 +996,8 @@ static void _worker_request_done_external(request_t *request, UNUSED rlm_rcode_t /** Internal request (i.e. one generated by the interpreter) is now complete * - * Whatever generated the request is now responsible for freeing it. + * Whatever generated the request is now responsible for freeing it, + * unless there's no talloc parent. In which case we have to free it. */ static void _worker_request_done_internal(request_t *request, UNUSED rlm_rcode_t rcode, void *uctx) { @@ -1006,6 +1007,8 @@ static void _worker_request_done_internal(request_t *request, UNUSED rlm_rcode_t fr_assert(!fr_heap_entry_inserted(request->runnable_id)); fr_assert(!fr_minmax_heap_entry_inserted(request->time_order_id)); + + if (!talloc_parent(request)) talloc_free(request); } /** Detached request (i.e. one generated by the interpreter with no parent) is now complete diff --git a/src/lib/server/trigger.c b/src/lib/server/trigger.c index c8f5fcee1b1..8a999f67235 100644 --- a/src/lib/server/trigger.c +++ b/src/lib/server/trigger.c @@ -457,11 +457,10 @@ int trigger_exec(unlang_interpret_t *intp, * shutting down. */ unlang_interpret_synchronous(NULL, request); - talloc_free(request); } /* - * Otherwise the worker cleans up the request request. + * Otherwise the worker cleans up the request. */ return 0; } diff --git a/src/lib/unlang/interpret_synchronous.c b/src/lib/unlang/interpret_synchronous.c index 60127080392..89218a7b524 100644 --- a/src/lib/unlang/interpret_synchronous.c +++ b/src/lib/unlang/interpret_synchronous.c @@ -71,12 +71,14 @@ static void _request_done_external(request_t *request, UNUSED rlm_rcode_t rcode, /** Internal request (i.e. one generated by the interpreter) is now complete * + * Whatever generated the request is now responsible for freeing it, + * unless there's no talloc parent. In which case we have to free it. */ static void _request_done_internal(request_t *request, UNUSED rlm_rcode_t rcode, UNUSED void *uctx) { RDEBUG3("Done synchronous internal request"); - /* Request will be cleaned up by whatever created it */ + if (!talloc_parent(request)) talloc_free(request); } static void _request_done_detached(request_t *request, UNUSED rlm_rcode_t rcode, UNUSED void *uctx)