From: Arran Cudbard-Bell Date: Mon, 2 Jul 2018 14:11:01 +0000 (-0400) Subject: Ensure proto_* modules loaded by listeners are freed correctly X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4a7556ebb706640344233126a16566525d59bfb3;p=thirdparty%2Ffreeradius-server.git Ensure proto_* modules loaded by listeners are freed correctly --- diff --git a/src/lib/util/talloc.c b/src/lib/util/talloc.c index 63a7cc69674..08e753f98ae 100644 --- a/src/lib/util/talloc.c +++ b/src/lib/util/talloc.c @@ -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 diff --git a/src/main/cf_util.c b/src/main/cf_util.c index 9de500b74e3..eb9d74b64dd 100644 --- a/src/main/cf_util.c +++ b/src/main/cf_util.c @@ -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; } diff --git a/src/main/dl.c b/src/main/dl.c index 8659005d174..4360047b2b9 100644 --- a/src/main/dl.c +++ b/src/main/dl.c @@ -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; } diff --git a/src/main/virtual_servers.c b/src/main/virtual_servers.c index 9f0aabec867..ceef9c8c09d 100644 --- a/src/main/virtual_servers.c +++ b/src/main/virtual_servers.c @@ -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; }