*/
struct tmpl_cursor_ctx_s {
TALLOC_CTX *ctx; //!< Temporary allocations go here.
-
+ TALLOC_CTX *pool; //!< Temporary pool.
tmpl_t const *vpt; //!< tmpl we're evaluating.
request_t *request; //!< Result of following the request references.
fr_pair_t **radius_list(request_t *request, pair_list_t list);
-fr_radius_packet_t *radius_packet(request_t *request, pair_list_t list_name);
+fr_radius_packet_t *radius_packet(request_t *request, pair_list_t list_name);
TALLOC_CTX *radius_list_ctx(request_t *request, pair_list_t list_name);
return NULL;
}
+static inline CC_HINT(always_inline)
+void _tmpl_cursor_pool_init(tmpl_cursor_ctx_t *cc)
+{
+ if (!cc->pool) MEM(cc->pool = talloc_pool(cc->ctx, sizeof(tmpl_cursor_nested_t) * 5));
+}
+
/** Initialise an evaluation ctx for traversing a TLV attribute
*
*/
break;
} else goto no_prev;
- MEM(ns = talloc_pooled_object(cc->ctx, tmpl_cursor_nested_t,
+ _tmpl_cursor_pool_init(cc);
+ MEM(ns = talloc_pooled_object(cc->pool, tmpl_cursor_nested_t,
1, sizeof(fr_cursor_stack_t) + (sizeof(fr_cursor_t) * span)));
*ns = (tmpl_cursor_nested_t){
.ar = ar,
{
tmpl_cursor_nested_t *ns;
- MEM(ns = talloc(cc->ctx, tmpl_cursor_nested_t));
+ _tmpl_cursor_pool_init(cc);
+ MEM(ns = talloc(cc->pool, tmpl_cursor_nested_t));
*ns = (tmpl_cursor_nested_t){
.ar = ar,
.func = _tmpl_cursor_group_eval,
};
fr_dlist_init(&cc->nested, tmpl_cursor_nested_t, entry);
- /*
- * Create a CHILD context, so that we don't have to track
- * any child allocations. We can just
- * talloc_free(cc->ctx) in tmpl_cursor_clear().
- */
- cc->ctx = talloc(cc->ctx, uint8_t);
-
/*
* Prime the stack!
*/
*/
void tmpl_cursor_clear(tmpl_cursor_ctx_t *cc)
{
+ TALLOC_FREE(cc->pool); /* just in case we somehow leaked memory */
+
if (!fr_dlist_num_elements(&cc->nested)) return;/* Help simplify dealing with unused cursor ctxs */
fr_dlist_remove(&cc->nested, &cc->leaf); /* Noop if leaf isn't inserted */
fr_dlist_talloc_free(&cc->nested);
-
- talloc_free(cc->ctx); /* free our private talloc ctx */
}
/** Copy pairs matching a #tmpl_t in the current #request_t