]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
interpreter: Allow frame states to be allocated without allocating memory for a frame...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 May 2020 23:00:41 +0000 (18:00 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 May 2020 23:00:41 +0000 (18:00 -0500)
It's useful for scratch space where we don't need to store state between calls

src/lib/unlang/interpret.c

index 90e0392234e3c832021e7bb9033361821bbecafe..60766f8ae8805ac2d37207a7fa5105e624e1ef4c 100644 (file)
@@ -119,29 +119,38 @@ static inline void frame_state_init(unlang_stack_t *stack, unlang_stack_frame_t
 {
        unlang_t const  *instruction = frame->instruction;
        unlang_op_t     *op;
+       char const      *name;
 
        op = &unlang_ops[instruction->type];
+       name = op->frame_state_name ? op->frame_state_name : __location__;
 
        frame->interpret = op->interpret;
        frame->signal = op->signal;
 
+#ifdef HAVE_TALLOC_ZERO_POOLED_OBJECT
        /*
-        *      The frame needs to track state.  Do so here.
+        *      Pooled object
         */
-       if (op->frame_state_size) {
-               char const *name = op->frame_state_name ? op->frame_state_name : __location__;
-
-#ifdef HAVE_TALLOC_ZERO_POOLED_OBJECT
-               if (op->frame_state_pool_size) {
-                       MEM(frame->state = _talloc_zero_pooled_object(stack,
-                                                                     op->frame_state_size, name,
-                                                                     op->frame_state_pool_objects,
-                                                                     op->frame_state_pool_size));
-               }
+       if (op->frame_state_pool_size && op->frame_state_size) {
+               MEM(frame->state = _talloc_zero_pooled_object(stack,
+                                                             op->frame_state_size, name,
+                                                             op->frame_state_pool_objects,
+                                                             op->frame_state_pool_size));
+       } else
 #endif
-               else {
-                       MEM(frame->state = _talloc_zero(stack, op->frame_state_size, name));
-               }
+       /*
+        *      Pool
+        */
+       if (op->frame_state_pool_size && !op->frame_state_size) {
+               MEM(frame->state = talloc_pool(stack,
+                                              op->frame_state_pool_size +
+                                              ((20 + 68 + 15) * op->frame_state_pool_objects))); /* from samba talloc.c */
+               talloc_set_name_const(frame->state, name);
+       /*
+        *      Object
+        */
+       } else if (op->frame_state_size) {
+               MEM(frame->state = _talloc_zero(stack, op->frame_state_size, name));
        }
 }