]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move to unlang_interpret_frame_talloc_ctx()
authorAlan T. DeKok <aland@freeradius.org>
Fri, 8 May 2020 18:12:23 +0000 (14:12 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 8 May 2020 18:13:00 +0000 (14:13 -0400)
instead of unlang_module_frame_talloc_ctx()

the new function is more generic, and can be used in more places.

src/lib/unlang/interpret.c
src/lib/unlang/interpret.h
src/lib/unlang/module.c
src/lib/unlang/module.h
src/modules/rlm_exec/rlm_exec.c

index 0ca7f8080fa3b4b98424938dde9e433db245a361..4d881085881c2325b0497e47d323b9014b6d3104 100644 (file)
@@ -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
index 60accbe26359c77c0e83c647b370af499f3fc6c8..b8bc5bcd314118e4db9b79009a0e8250dc3c79b0 100644 (file)
@@ -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
 }
index 418aed7c08dbe79fedd8d07694bdb1d253f42445..f991d3db9841ce2b8378f75b723363bd9a309da6 100644 (file)
@@ -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,
index da1411e99f5df56270934283ccf68909eb7dc082..4dd87f429243404278244f2263a3fad3478ea499 100644 (file)
@@ -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
index f8bd524f4052be4b0785504b198d32af832a4a8f..b30a2a5c5ec2efe80aea4932041f1d610562e697 100644 (file)
@@ -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.