From: Alan T. DeKok Date: Fri, 8 May 2020 18:12:23 +0000 (-0400) Subject: move to unlang_interpret_frame_talloc_ctx() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02da44a8d9e8b48b271394a52eef901d52dfd9f6;p=thirdparty%2Ffreeradius-server.git move to unlang_interpret_frame_talloc_ctx() instead of unlang_module_frame_talloc_ctx() the new function is more generic, and can be used in more places. --- diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 0ca7f8080fa..4d881085881 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -1185,6 +1185,33 @@ void unlang_interpret_resumable(REQUEST *request) } +/** Get a talloc_ctx which is valid only for this frame + * + * @param[in] request The current request. + * @return + * - a TALLOC_CTX which is valid only for this stack frame + */ +TALLOC_CTX *unlang_interpret_frame_talloc_ctx(REQUEST *request) +{ + unlang_stack_t *stack = request->stack; + unlang_stack_frame_t *frame = &stack->frame[stack->depth]; + + switch (frame->instruction->type) { + default: + break; + + case UNLANG_TYPE_MODULE: + case UNLANG_TYPE_XLAT: + return (TALLOC_CTX *) frame->state; + } + + /* + * Ensure that the memory is always cleaned up when the + * request exits. And make sure that this function is safe to call from anywhere. + */ + return (TALLOC_CTX *) request; +} + /** Get information about the interpreter state * * @ingroup xlat_functions diff --git a/src/lib/unlang/interpret.h b/src/lib/unlang/interpret.h index 60accbe2635..b8bc5bcd314 100644 --- a/src/lib/unlang/interpret.h +++ b/src/lib/unlang/interpret.h @@ -119,6 +119,8 @@ int unlang_interpret_stack_depth(REQUEST *request); rlm_rcode_t unlang_interpret_stack_result(REQUEST *request); +TALLOC_CTX *unlang_interpret_frame_talloc_ctx(REQUEST *request); + void unlang_interpret_init(void); #ifdef __cplusplus } diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index 418aed7c08d..f991d3db984 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -855,22 +855,6 @@ done: return UNLANG_ACTION_CALCULATE_RESULT; } -/** Yield a request back to the interpreter from within a module - * - * @param[in] request The current request. - * @return - * - a TALLOC_CTX which is valid only for this stack frame - */ -TALLOC_CTX *unlang_module_frame_talloc_ctx(REQUEST *request) -{ - unlang_stack_t *stack = request->stack; - unlang_stack_frame_t *frame = &stack->frame[stack->depth]; - - unlang_frame_state_module_t *state = talloc_get_type_abort(frame->state, unlang_frame_state_module_t); - - return (TALLOC_CTX *) state; -} - void unlang_module_init(void) { unlang_register(UNLANG_TYPE_MODULE, diff --git a/src/lib/unlang/module.h b/src/lib/unlang/module.h index da1411e99f5..4dd87f42924 100644 --- a/src/lib/unlang/module.h +++ b/src/lib/unlang/module.h @@ -139,8 +139,6 @@ rlm_rcode_t unlang_module_yield(REQUEST *request, fr_unlang_module_resume_t resume, fr_unlang_module_signal_t signal, void *rctx); -TALLOC_CTX *unlang_module_frame_talloc_ctx(REQUEST *request); - #ifdef __cplusplus } #endif diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index f8bd524f405..b30a2a5c5ec 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -347,7 +347,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_exec_dispatch(void *instance, UNUSED voi /* * Get frame-local talloc ctx */ - ctx = unlang_module_frame_talloc_ctx(request); + ctx = unlang_interpret_frame_talloc_ctx(request); /* * Do the asynchronous xlat expansion.