return memcmp(a->name, b->name, a_len);
}
-
/*
* find the appropriate registered xlat function.
*/
* @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;
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.
} 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;
}
} 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;
}
/*
* 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;
*/
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);
}