From: Arran Cudbard-Bell Date: Wed, 24 May 2017 23:08:45 +0000 (-0400) Subject: Alloc a pooled object for the stack, so we can use mutable frame extensions without... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10d8d8f8cd34fc74890977c8b5daaf779925ba55;p=thirdparty%2Ffreeradius-server.git Alloc a pooled object for the stack, so we can use mutable frame extensions without leaking request pool memory --- diff --git a/src/include/interpreter.h b/src/include/interpreter.h index fb87483e302..fbc25e65eac 100644 --- a/src/include/interpreter.h +++ b/src/include/interpreter.h @@ -218,6 +218,12 @@ typedef struct { unlang_t *found; } unlang_stack_entry_redundant_t; +typedef union { + unlang_stack_entry_modcall_t modcall; //!< State for a modcall. + unlang_stack_entry_foreach_t foreach; //!< Foreach iterator state. + unlang_stack_entry_redundant_t redundant; //!< Redundant section state. +} unlang_stack_entry_t; + /** Our interpreter stack, as distinct from the C stack * * We don't call the modules recursively. Instead we iterate over a list of #unlang_t and diff --git a/src/main/request.c b/src/main/request.c index 863b9533cae..d593e3fd498 100644 --- a/src/main/request.c +++ b/src/main/request.c @@ -110,7 +110,26 @@ REQUEST *request_alloc(TALLOC_CTX *ctx) request->module = NULL; request->component = ""; + +#ifdef HAVE_TALLOC_POOLED_OBJECT + /* + * If we have talloc_pooled_object allocate the + * stack as a combined chunk/pool, with memory + * to hold at mutable data for at least a quarter + * of the maximum number of stack frames. + * + * Having a dedicated pool for mutable stack data + * means we don't have memory fragmentations issues + * as we would if request were used as the pool. + * + * This number is pretty arbitrary, but it seems + * like too low level to make into a tuneable. + */ + request->stack = talloc_pooled_object(request, unlang_stack_t, UNLANG_STACK_MAX / 4, + sizeof(unlang_stack_entry_t)); +#else request->stack = talloc_zero(request, unlang_stack_t); +#endif request->heap_id = -1; request->state_ctx = talloc_init("session-state");