From: Arran Cudbard-Bell Date: Tue, 21 Jun 2022 14:41:25 +0000 (-0500) Subject: Automatically allocate a frame ctx when asked X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=490ad07dea058eb18c98ff3afa9a60580d9764d0;p=thirdparty%2Ffreeradius-server.git Automatically allocate a frame ctx when asked --- diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index fbb381a786b..dde59f21bae 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -1242,48 +1242,14 @@ TALLOC_CTX *unlang_interpret_frame_talloc_ctx(request_t *request) unlang_stack_t *stack = request->stack; unlang_stack_frame_t *frame = &stack->frame[stack->depth]; - switch (frame->instruction->type) { - case UNLANG_TYPE_MODULE: - case UNLANG_TYPE_FUNCTION: - case UNLANG_TYPE_REDUNDANT: - case UNLANG_TYPE_LOAD_BALANCE: - case UNLANG_TYPE_REDUNDANT_LOAD_BALANCE: - case UNLANG_TYPE_PARALLEL: - case UNLANG_TYPE_IF: - case UNLANG_TYPE_FILTER: - case UNLANG_TYPE_UPDATE: - case UNLANG_TYPE_SWITCH: - case UNLANG_TYPE_FOREACH: - case UNLANG_TYPE_MAP: - case UNLANG_TYPE_SUBREQUEST: - case UNLANG_TYPE_CALL: - case UNLANG_TYPE_EDIT: - case UNLANG_TYPE_XLAT: - case UNLANG_TYPE_TMPL: - return (TALLOC_CTX *) frame->state; - - case UNLANG_TYPE_GROUP: - case UNLANG_TYPE_ELSE: - case UNLANG_TYPE_ELSIF: - case UNLANG_TYPE_CASE: - case UNLANG_TYPE_BREAK: - case UNLANG_TYPE_RETURN: - case UNLANG_TYPE_DETACH: - case UNLANG_TYPE_CALLER: - case UNLANG_TYPE_POLICY: - break; - - case UNLANG_TYPE_NULL: - case UNLANG_TYPE_MAX: - fr_assert(0); - break; - } + if (frame->state) 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. + * If the frame doesn't ordinarily have a + * state, assume the caller knows what it's + * doing and allocate one. */ - return (TALLOC_CTX *)request; + return (TALLOC_CTX *)frame->state = talloc_new(request); } static xlat_arg_parser_t const unlang_interpret_xlat_args[] = {