]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add function to convert XLAT_FUNC to other type
authorAlan T. DeKok <aland@freeradius.org>
Mon, 30 May 2022 20:49:59 +0000 (16:49 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2022 11:15:50 +0000 (07:15 -0400)
only in limited situations, and only if we can't leak memory.

src/lib/unlang/xlat_inst.c
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_purify.c

index 730db55082202552880d4b46985a04dade122ddc..1b9ab3918ac29daad8ccc0d55e5c8248fd3fa2d8 100644 (file)
@@ -611,3 +611,37 @@ void xlat_instances_free(void)
         */
        while (xlat_inst_tree && (xi = fr_heap_pop(&xlat_inst_tree))) talloc_free(xi);
 }
+
+/** Remove a node from the list of xlat instance data
+ *
+ */
+int xlat_inst_remove(xlat_exp_t *node)
+{
+       int ret;
+
+       fr_assert(node->type == XLAT_FUNC);
+       fr_assert(!node->call.func->detach);
+       fr_assert(!node->call.func->thread_detach);
+
+       if (node->call.inst) {
+               ret = fr_heap_extract(&xlat_inst_tree, node->call.inst);
+               if (ret < 0) return ret;
+
+               talloc_set_destructor(node->call.inst, NULL);
+               TALLOC_FREE(node->call.inst);
+       }
+
+       if (node->call.thread_inst) {
+               if (!node->call.ephemeral) {
+                       ret = fr_heap_extract(&xlat_thread_inst_tree, node->call.thread_inst);
+                       if (ret < 0) return ret;
+               }
+
+               talloc_set_destructor(node->call.thread_inst, NULL);
+               TALLOC_FREE(node->call.inst);
+       }
+
+
+       node->type = XLAT_INVALID;
+       return 0;
+}
index c4d5cab4b597f3167c2ffdb407cc2ce3234e8f00..1188a8818ade61cdf690cbe20b722d3f35fa9d27 100644 (file)
@@ -348,6 +348,11 @@ int                xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in,
 
 ssize_t                xlat_print_node(fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t const *node, fr_sbuff_escape_rules_t const *e_rules);
 
+/*
+ *     xlat_inst.c
+ */
+int            xlat_inst_remove(xlat_exp_t *node);
+
 static inline xlat_exp_t *xlat_exp_head(xlat_exp_head_t const *head)
 {
        if (!head) return NULL;
index d03234f17201504bc4bef6eaa2001d6fb3fb174b..1f455ee77fbf4a8161f2b2c2aa3c17e806aefbf9 100644 (file)
@@ -125,11 +125,13 @@ static int xlat_purify_list(xlat_exp_head_t *head, request_t *request)
                        if (!success) return -1;
 
                        /*
-                        *      The function call becomes a GROUP of
-                        *      boxes.  We just re-use the argument head, which is already of the type we need.
+                        *      The function call becomes a GROUP of boxes.  We just re-use the argument head,
+                        *      which is already of the type we need.
                         */
                        group = node->call.args;
                        fr_dlist_talloc_free(&group->dlist);
+
+                       xlat_inst_remove(node);
                        node->type = XLAT_GROUP;
                        node->group = group;