Skip to content

Commit

Permalink
Fix protocol dlopen handle 'leak' CID 1004305
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Mar 21, 2014
1 parent 9d9f4d0 commit 5b4fa6d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/listen.c
Expand Up @@ -2721,6 +2721,12 @@ rad_listen_t *proxy_new_listener(home_server_t *home, int src_port)
}
#endif

static int _free_proto_handle(lt_dlhandle *handle)
{
dlclose(*handle);
return 0;
}

static rad_listen_t *listen_parse(CONF_SECTION *cs, char const *server)
{
int type, rcode;
Expand Down Expand Up @@ -2750,6 +2756,7 @@ static rad_listen_t *listen_parse(CONF_SECTION *cs, char const *server)
handle = lt_dlopenext(buffer);
if (handle) {
fr_protocol_t *proto;
lt_dlhandle *marker;

proto = dlsym(handle, buffer);
if (!proto) {
Expand Down Expand Up @@ -2798,9 +2805,11 @@ static rad_listen_t *listen_parse(CONF_SECTION *cs, char const *server)
memcpy(&master_listen[type], proto, sizeof(*proto));

/*
* And throw away the handle.
* @todo: fix it later
* Ensure handle gets closed if config section gets freed
*/
marker = talloc(cs, lt_dlhandle);
*marker = handle;
talloc_set_destructor(marker, _free_proto_handle);

if (master_listen[type].magic != RLM_MODULE_INIT) {
ERROR("Failed to load protocol '%s' due to internal sanity check problem",
Expand Down

0 comments on commit 5b4fa6d

Please sign in to comment.