mirror of
https://github.com/troglobit/finit.git
synced 2026-11-02 13:20:32 +00:00
Fix Coverity CID CID 56281: Resource leak (RESOURCE_LEAK)
Initial support for unloading plugins. Currently we only save dlopen() handle. The plugin_unregister() function itself is never called atm. This should at the very least make Coverity happy. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
dd7f0ce090
commit
ad8ae4af91
2 files changed
+27
-10
No files matched your search
@@ -36,8 +36,8 @@
|
|||||||
|
|
||||||
#define is_io_plugin(p) ((p)->io.cb && (p)->io.fd >= 0)
|
#define is_io_plugin(p) ((p)->io.cb && (p)->io.fd >= 0)
|
||||||
|
|
||||||
static char *plugpath = NULL; /* Set by first load. */
|
static char *plugpath = NULL; /* Set by first load. */
|
||||||
static TAILQ_HEAD(, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins);
|
static TAILQ_HEAD(plugin_head, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins);
|
||||||
|
|
||||||
static void check_plugin_depends(plugin_t *plugin);
|
static void check_plugin_depends(plugin_t *plugin);
|
||||||
|
|
||||||
@@ -81,12 +81,17 @@ int plugin_unregister(plugin_t *plugin)
|
|||||||
svc_t *svc = svc_find(plugin->name);
|
svc_t *svc = svc_find(plugin->name);
|
||||||
|
|
||||||
if (svc) {
|
if (svc) {
|
||||||
svc->cb = NULL;
|
svc->cb = NULL;
|
||||||
svc->dynamic = 0;
|
svc->dynamic = 0;
|
||||||
|
svc->dynamic_stop = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: Unfinished, add cleanup code here! */
|
/* Unload plugin */
|
||||||
|
if (dlclose(plugin->handle)) {
|
||||||
|
_e("Failed unloading %s ...", plugin->name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -202,8 +207,9 @@ static void init_plugins(uev_ctx_t *ctx)
|
|||||||
static int load_one(char *path, char *name)
|
static int load_one(char *path, char *name)
|
||||||
{
|
{
|
||||||
int noext;
|
int noext;
|
||||||
char plugin[CMD_SIZE];
|
char sofile[CMD_SIZE];
|
||||||
void *handle;
|
void *handle;
|
||||||
|
plugin_t *plugin;
|
||||||
|
|
||||||
if (!path || !fisdir(path) || !name) {
|
if (!path || !fisdir(path) || !name) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@@ -212,18 +218,26 @@ static int load_one(char *path, char *name)
|
|||||||
|
|
||||||
/* Compose full path, with optional .so extension, to plugin */
|
/* Compose full path, with optional .so extension, to plugin */
|
||||||
noext = strcmp(name + strlen(name) - 3, ".so");
|
noext = strcmp(name + strlen(name) - 3, ".so");
|
||||||
snprintf(plugin, sizeof(plugin), "%s/%s%s", path, name, noext ? ".so" : "");
|
snprintf(sofile, sizeof(sofile), "%s/%s%s", path, name, noext ? ".so" : "");
|
||||||
|
|
||||||
_d("Loading plugin %s ...", basename(plugin));
|
_d("Loading plugin %s ...", basename(sofile));
|
||||||
/* Ignore leak, we do not support unloading of plugins atm.
|
/* Ignore leak, we do not support unloading of plugins atm.
|
||||||
* TODO: Add handle to list of loaded plugins, dlclose() on
|
* TODO: Add handle to list of loaded plugins, dlclose() on
|
||||||
* plugin_unregister() */
|
* plugin_unregister() */
|
||||||
handle = dlopen(plugin, RTLD_LAZY | RTLD_GLOBAL);
|
handle = dlopen(sofile, RTLD_LAZY | RTLD_GLOBAL);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
_e("Failed loading plugin %s: %s", plugin, dlerror());
|
_e("Failed loading plugin %s: %s", sofile, dlerror());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Remember handle from dlopen() for plugin_unregister() */
|
||||||
|
plugin = TAILQ_LAST(&plugins, plugin_head);
|
||||||
|
if (!plugin) {
|
||||||
|
_e("Plugin %s failed to register.", sofile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
plugin->handle = handle;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ typedef struct plugin {
|
|||||||
/* BSD sys/queue.h linked list node. */
|
/* BSD sys/queue.h linked list node. */
|
||||||
TAILQ_ENTRY(plugin) link;
|
TAILQ_ENTRY(plugin) link;
|
||||||
|
|
||||||
|
/* Handle to be sent to dlclose() when plugins is unloaded. */
|
||||||
|
void *handle;
|
||||||
|
|
||||||
/* Event loop handler, used internally by Finit */
|
/* Event loop handler, used internally by Finit */
|
||||||
uev_t watcher;
|
uev_t watcher;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user