]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
*actually* deregister all the xlat functions when the tree is freed
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 23 Mar 2018 13:40:46 +0000 (13:40 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 23 Mar 2018 13:40:46 +0000 (13:40 +0000)
src/main/xlat_func.c

index 816199f6d5469f3533a410ed2503621910d00fd4..743b7e26feea09fd607558e70be7214092f59f40 100644 (file)
@@ -582,7 +582,6 @@ static int xlat_cmp(void const *one, void const *two)
        return memcmp(a->name, b->name, a_len);
 }
 
-
 /*
  *     find the appropriate registered xlat function.
  */
@@ -604,7 +603,7 @@ xlat_t *xlat_func_find(char const *name)
  * @param[in] xlat     to free.
  * @return 0
  */
-static int _xlat_free(xlat_t *xlat)
+static int _xlat_func_talloc_free(xlat_t *xlat)
 {
        if (!xlat_root) return 0;
 
@@ -614,6 +613,14 @@ static int _xlat_free(xlat_t *xlat)
        return 0;
 }
 
+/** Callback for the rbtree to clear out any xlats still registered
+ *
+ */
+static void _xlat_func_tree_free(void *xlat)
+{
+       talloc_free(xlat);
+}
+
 /** Register an xlat function.
  *
  * @param[in] mod_inst         Instance of module that's registering the xlat function.
@@ -667,7 +674,7 @@ int xlat_register(void *mod_inst, char const *name,
        } else {
                c = talloc_zero(xlat_root, xlat_t);
                c->name = talloc_typed_strdup(c, name);
-               talloc_set_destructor(c, _xlat_free);
+               talloc_set_destructor(c, _xlat_func_talloc_free);
                new = true;
        }
 
@@ -764,7 +771,7 @@ int _xlat_async_register(TALLOC_CTX *ctx,
        } else {
                c = talloc_zero(ctx, xlat_t);
                c->name = talloc_typed_strdup(c, name);
-               talloc_set_destructor(c, _xlat_free);
+               talloc_set_destructor(c, _xlat_func_talloc_free);
                new = true;
        }
 
@@ -1182,7 +1189,7 @@ int xlat_init(void)
        /*
         *      Create the function tree
         */
-       xlat_root = rbtree_create(NULL, xlat_cmp, NULL, RBTREE_FLAG_REPLACE);
+       xlat_root = rbtree_create(NULL, xlat_cmp, _xlat_func_tree_free, RBTREE_FLAG_REPLACE);
        if (!xlat_root) {
                ERROR("%s: Failed to create tree", __FUNCTION__);
                return -1;
@@ -1232,7 +1239,9 @@ int xlat_init(void)
  */
 void xlat_free(void)
 {
-       TALLOC_FREE(xlat_root);
+       rbtree_t *xr = xlat_root;               /* Make sure the tree can't be freed multiple times */
+       xlat_root = NULL;
+       talloc_free(xr);
 }