From: Alan T. DeKok Date: Wed, 6 Jul 2022 14:20:28 +0000 (-0400) Subject: add cf_item_free_children() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cbc92de7ff38d1e7a7b30e71df6980951cace4dd;p=thirdparty%2Ffreeradius-server.git add cf_item_free_children() for use with if (0) { ... }, so that unused xlats can be freed. Otherwise they're stuck in the instantiation tree, and will cause issues. --- diff --git a/src/lib/server/cf_util.c b/src/lib/server/cf_util.c index 36e5fec20d0..3cad91c80b7 100644 --- a/src/lib/server/cf_util.c +++ b/src/lib/server/cf_util.c @@ -2196,3 +2196,15 @@ void _cf_debug(CONF_ITEM const *ci) } } } + +/* + * Used when we don't need the children any more, as with + * + * if (0) { ... } + */ +void cf_item_free_children(CONF_ITEM *ci) +{ + fr_dlist_talloc_free(&ci->children); + TALLOC_FREE(ci->ident1); + TALLOC_FREE(ci->ident2); +} diff --git a/src/lib/server/cf_util.h b/src/lib/server/cf_util.h index 476b0f2716f..ff1f1836ecb 100644 --- a/src/lib/server/cf_util.h +++ b/src/lib/server/cf_util.h @@ -128,6 +128,8 @@ void _cf_filename_set(CONF_ITEM *cs, char const *filename); #define cf_lineno_set(_ci, _lineno) _cf_lineno_set(CF_TO_ITEM(_ci), _lineno) void _cf_lineno_set(CONF_ITEM *cs, int lineno); +void cf_item_free_children(CONF_ITEM *ci); + /* * Section manipulation and searching */ @@ -168,6 +170,9 @@ char const *cf_section_argv(CONF_SECTION const *cs, int argc); fr_token_t cf_section_name2_quote(CONF_SECTION const *cs); fr_token_t cf_section_argv_quote(CONF_SECTION const *cs, int argc); +#define cf_section_free_children(_x) cf_item_free_children(cf_section_to_item(_x)) + + /* * Pair manipulation and searching */ diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 970daa95cbf..eeac4464808 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -3070,9 +3070,12 @@ static unlang_t *compile_if_subsection(unlang_t *parent, unlang_compile_t *unlan cf_log_debug_prefix(cs, "Skipping contents of '%s' as it is always 'false'", unlang_ops[ext->type].name); - c = compile_section(parent, unlang_ctx, cs, ext); - talloc_free(c); - + /* + * Free the children, which frees any xlats, + * conditions, etc. which were defined, but are + * now entirely unused. + */ + cf_section_free_children(cs); c = compile_empty(parent, unlang_ctx, cs, ext); } else {