]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allocate dl_loader from a new context
authorAlan T. DeKok <aland@freeradius.org>
Thu, 1 Nov 2018 14:03:25 +0000 (10:03 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 1 Nov 2018 14:03:25 +0000 (10:03 -0400)
because we reference count proto_foo_* as new connections are
opened.

src/lib/server/dl.c

index af5cb1a084a981436136534c875032532013ce9a..9d9757651d05fe87961a7c6544775d001849ee5d 100644 (file)
@@ -371,13 +371,6 @@ static int _dl_free(dl_t *module)
 
        rbtree_deletebydata(dl_loader->tree, module);
 
-       /*
-        *      If everything has been freed, autofree the tree.
-        *      dl *MUST* be set to NULL, so that if the server decides to
-        *      load more modules, the tree is recreated.
-        */
-       if (rbtree_num_elements(dl_loader->tree) == 0) TALLOC_FREE(dl_loader);
-
        return 0;
 }
 
@@ -970,6 +963,7 @@ static int _dl_loader_free(dl_loader_t *dl_l)
        if (ret != 0) WARN("This may appear as a leak in talloc memory reports");
 #endif
 
+       dl_loader = NULL;
        return ret;
 }
 
@@ -980,7 +974,7 @@ int dl_loader_init(TALLOC_CTX *ctx, char const *lib_dir)
 {
        if (dl_loader) return 0;
 
-       dl_loader = talloc_zero(ctx, dl_loader_t);
+       dl_loader = talloc_zero(NULL, dl_loader_t);
        dl_loader->tree = rbtree_talloc_create(dl_loader, dl_handle_cmp, dl_t, NULL, 0);
        if (!dl_loader->tree) {
                ERROR("Failed initialising dl->tree");
@@ -989,6 +983,8 @@ int dl_loader_init(TALLOC_CTX *ctx, char const *lib_dir)
                return -1;
        }
 
+       talloc_link_ctx(ctx, dl_loader);
+
        dl_loader->inst_tree = rbtree_talloc_create(dl_loader, dl_inst_cmp, dl_instance_t, NULL, 0);
        if (!dl_loader->inst_tree) {
                ERROR("Failed initialising dl->inst_tree");