Skip to content

Commit

Permalink
dlclose() plugins on shutdown
Browse files Browse the repository at this point in the history
We suppressed/ignored the warning about leaking the dlopen handles long
ago in Coverity, since the plugins stay loaded for the life of the
daemon.  However, with the current fork->execve model used for
"replace", I can't be sure that leaking unclosed dlopen handles doesn't
cause some kind of actual resource leak, especially on platforms I don't
regularly test.  Modern Linux/glibc doesn't show any visible leakage
from it, but better safe than sorry since it's a simple fix.
  • Loading branch information
blblack committed Sep 11, 2018
1 parent bfd67ab commit 0083d8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/gdnsd/plugapi.h
Expand Up @@ -124,6 +124,7 @@ typedef void (*gdnsd_start_monitors_cb_t)(struct ev_loop* mon_loop);
// pointers for all of the possibly-documented callbacks
typedef struct {
const char* name;
void* handle;
bool config_loaded;
gdnsd_load_config_cb_t load_config;
gdnsd_map_res_cb_t map_res;
Expand Down
7 changes: 5 additions & 2 deletions libgdnsd/plugapi.c
Expand Up @@ -249,6 +249,8 @@ static plugin_t* gdnsd_plugin_load(const char* pname)
pname, apiv_bopt, this_bopt);
}

plug->handle = pptr;

# define PSETFUNC(x) plug->x = (gdnsd_ ## x ## _cb_t)plugin_dlsym(pptr, pname, #x);
PSETFUNC(load_config)
PSETFUNC(map_res)
Expand All @@ -264,8 +266,6 @@ static plugin_t* gdnsd_plugin_load(const char* pname)
PSETFUNC(start_monitors)
# undef PSETFUNC

// leak of dlopen() handle "pptr" here is intentional. The code has no further
// use for it at this point, and we never dlclose() the plugins...
return plug;
}

Expand Down Expand Up @@ -327,4 +327,7 @@ void gdnsd_plugins_action_exit(void)
for (unsigned i = 0; i < num_plugins; i++)
if (plugins[i]->exit)
plugins[i]->exit();
for (unsigned i = 0; i < num_plugins; i++)
if (dlclose(plugins[i]->handle))
log_fatal("Failed to close() the '%s' plugin: %s", plugins[i]->name, dlerror());
}

0 comments on commit 0083d8f

Please sign in to comment.