Skip to content

Commit

Permalink
Automatically remove xlat's when we free a module instance
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Oct 29, 2014
1 parent 156acba commit 7bfae92
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
7 changes: 7 additions & 0 deletions src/main/modules.c
Expand Up @@ -392,6 +392,13 @@ static void module_instance_free(void *data)

xlat_unregister(this->name, NULL, this->insthandle);

/*
* Remove all xlat's registered to this instance.
*/
if (this->insthandle) {
xlat_unregister_module(this->insthandle);
}

#ifndef NDEBUG
memset(this, 0, sizeof(*this));
#endif
Expand Down
13 changes: 1 addition & 12 deletions src/modules/proto_dhcp/rlm_dhcp.c
Expand Up @@ -117,17 +117,6 @@ static ssize_t dhcp_xlat(UNUSED void *instance, REQUEST *request, char const *fm
return fr_bin2hex(out, binbuf, len);
}

/*
* Only free memory we allocated. The strings allocated via
* cf_section_parse() do not need to be freed.
*/
static int mod_detach(void *instance)
{
xlat_unregister("dhcp_options", dhcp_options_xlat, instance);
xlat_unregister("dhcp", dhcp_xlat, instance);
return 0;
}


/*
* Instantiate the module.
Expand Down Expand Up @@ -184,7 +173,7 @@ module_t rlm_dhcp = {
sizeof(rlm_dhcp_t),
NULL, /* CONF_PARSER */
mod_instantiate, /* instantiation */
mod_detach, /* detach */
NULL, /* detach */
{
NULL, /* authentication */
NULL, /* authorization */
Expand Down
2 changes: 0 additions & 2 deletions src/modules/rlm_rest/rlm_rest.c
Expand Up @@ -771,8 +771,6 @@ static int mod_detach(void *instance)

fr_connection_pool_delete(inst->conn_pool);

xlat_unregister(inst->xlat_name, rest_xlat, instance);

/* Free any memory used by libcurl */
rest_cleanup();

Expand Down
7 changes: 0 additions & 7 deletions src/modules/rlm_unbound/rlm_unbound.c
Expand Up @@ -697,9 +697,6 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
xlat_register(inst->xlat_aaaa_name, xlat_aaaa, NULL, inst) ||
xlat_register(inst->xlat_ptr_name, xlat_ptr, NULL, inst)) {
ERROR("rlm_unbound (%s): Failed registering xlats", inst->name);
xlat_unregister(inst->xlat_a_name, xlat_a, inst);
xlat_unregister(inst->xlat_aaaa_name, xlat_aaaa, inst);
xlat_unregister(inst->xlat_ptr_name, xlat_ptr, inst);
goto error_nores;
}
return 0;
Expand All @@ -717,10 +714,6 @@ static int mod_detach(UNUSED void *instance)
{
rlm_unbound_t *inst = instance;

xlat_unregister(inst->xlat_a_name, xlat_a, inst);
xlat_unregister(inst->xlat_aaaa_name, xlat_aaaa, inst);
xlat_unregister(inst->xlat_ptr_name, xlat_ptr, inst);

if (inst->log_fd >= 0) {
fr_event_fd_delete(inst->el, 0, inst->log_fd);
if (inst->ub) {
Expand Down

0 comments on commit 7bfae92

Please sign in to comment.