]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Automatically allocate a frame ctx when asked
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 21 Jun 2022 14:41:25 +0000 (09:41 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 21 Jun 2022 14:41:25 +0000 (09:41 -0500)
src/lib/unlang/interpret.c

index fbb381a786b7b077bd6a712ae99030ea7fc21331..dde59f21baee4f9213440aba24e80072c5da97af 100644 (file)
@@ -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[] = {