]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Ensure proto_* modules loaded by listeners are freed correctly
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 2 Jul 2018 14:11:01 +0000 (10:11 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 2 Jul 2018 14:11:01 +0000 (10:11 -0400)
src/lib/util/talloc.c
src/main/cf_util.c
src/main/dl.c
src/main/virtual_servers.c

index 63a7cc69674902ef4de53349e56d50aaa50ffbeb..08e753f98aefa8899fc3bae760095fa20f3369b4 100644 (file)
@@ -339,7 +339,11 @@ void talloc_decrease_ref_count(void const *ptr)
 
        memcpy(&to_free, &ptr, sizeof(to_free));
 
-       talloc_unlink(talloc_parent(ptr), to_free);
+       if (talloc_reference_count(to_free) == 0) {
+               talloc_free(to_free);
+       } else {
+               talloc_unlink(talloc_parent(ptr), to_free);
+       }
 }
 
 /** Add a NULL pointer to an array of pointers
index 9de500b74e3dd43267e1d75fdc85d9f0f1a11b4b..eb9d74b64dd28355eb0f7bee17685892fdd1b5c8 100644 (file)
@@ -1327,7 +1327,7 @@ static int _cd_free(CONF_DATA *cd)
 
        memcpy(&to_free, &cd->data, sizeof(to_free));
 
-       if (cd->free) talloc_free(to_free);
+       if (cd->free) talloc_decrease_ref_count(to_free);       /* Also works OK for non-reference counted chunks */
 
        return 0;
 }
index 8659005d174057c36ad7cf250bb9725fefba1599..4360047b2b9e76e5da6f47f58395d3c19dcb5b5d 100644 (file)
@@ -373,10 +373,7 @@ static int _dl_free(dl_t *module)
         *      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) {
-               ERROR("Freeing dl loader");
-               TALLOC_FREE(dl_loader);
-       }
+       if (rbtree_num_elements(dl_loader->tree) == 0) TALLOC_FREE(dl_loader);
 
        return 0;
 }
index 9f0aabec867fe1bb09b535420e685c451233d30c..ceef9c8c09d8c17ad85eacd985360403d9dd1712 100644 (file)
@@ -166,13 +166,16 @@ static int listen_on_read(UNUSED TALLOC_CTX *ctx, UNUSED void *out, UNUSED void
        CONF_SECTION            *listen_cs = cf_item_to_section(ci);
        CONF_SECTION            *server_cs = cf_item_to_section(cf_parent(ci));
        CONF_PAIR               *namespace = cf_pair_find(server_cs, "namespace");
+       dl_t const              *module;
 
        if (DEBUG_ENABLED4) cf_log_debug(ci, "Loading proto_%s", cf_pair_value(namespace));
 
-       if (!dl_module(listen_cs, NULL, cf_pair_value(namespace), DL_TYPE_PROTO)) {
+       module = dl_module(listen_cs, NULL, cf_pair_value(namespace), DL_TYPE_PROTO);
+       if (!module) {
                cf_log_err(listen_cs, "Failed loading proto_%s module", cf_pair_value(namespace));
                return -1;
        }
+       cf_data_add(listen_cs, module, "proto module", true);
 
        return 0;
 }