]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add cf_item_free_children()
authorAlan T. DeKok <aland@freeradius.org>
Wed, 6 Jul 2022 14:20:28 +0000 (10:20 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 6 Jul 2022 15:41:52 +0000 (11:41 -0400)
for use with if (0) { ... }, so that unused xlats can be freed.
Otherwise they're stuck in the instantiation tree, and will cause
issues.

src/lib/server/cf_util.c
src/lib/server/cf_util.h
src/lib/unlang/compile.c

index 36e5fec20d01b5e58b128171b550f8a50ea57c35..3cad91c80b7acdc6c0ec0e2c0c3350ba3189611b 100644 (file)
@@ -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);
+}
index 476b0f2716fdf817ab09e21daa104064fffca575..ff1f1836ecbd5f5909c6a5ed8e9214d2b899c981 100644 (file)
@@ -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
  */
index 970daa95cbf390bb16c0ea78aa4cbb8623bd93eb..eeac446480865f033fd6db9a7c53966e1c5e086f 100644 (file)
@@ -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 {