mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +00:00
plugin: free allocated plugin descriptor
plugin.c:123:3: warning: Potential leak of memory pointed to by 'd' dlclose(h); ^~~~~~~ Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
08ed62d761
commit
0d45dd691e
@@ -96,6 +96,7 @@ static int cr_lib_load(int stage, char *path)
|
|||||||
plugin_desc_t *this;
|
plugin_desc_t *this;
|
||||||
size_t i;
|
size_t i;
|
||||||
void *h;
|
void *h;
|
||||||
|
bool allocated = false;
|
||||||
|
|
||||||
h = dlopen(path, RTLD_LAZY);
|
h = dlopen(path, RTLD_LAZY);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
@@ -110,25 +111,22 @@ static int cr_lib_load(int stage, char *path)
|
|||||||
* be changing own format frequently.
|
* be changing own format frequently.
|
||||||
*/
|
*/
|
||||||
d = dlsym(h, "CR_PLUGIN_DESC");
|
d = dlsym(h, "CR_PLUGIN_DESC");
|
||||||
if (!d)
|
|
||||||
d = cr_gen_plugin_desc(h, path);
|
|
||||||
if (!d) {
|
if (!d) {
|
||||||
pr_err("Can't load plugin %s\n", path);
|
d = cr_gen_plugin_desc(h, path);
|
||||||
dlclose(h);
|
if (!d) {
|
||||||
return -1;
|
pr_err("Can't load plugin %s\n", path);
|
||||||
|
goto error_close;
|
||||||
|
}
|
||||||
|
allocated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this = xzalloc(sizeof(*this));
|
this = xzalloc(sizeof(*this));
|
||||||
if (!this) {
|
if (!this)
|
||||||
dlclose(h);
|
goto error_close;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verify_plugin(d)) {
|
if (verify_plugin(d)) {
|
||||||
pr_err("Corrupted plugin %s\n", path);
|
pr_err("Corrupted plugin %s\n", path);
|
||||||
xfree(this);
|
goto error_free;
|
||||||
dlclose(h);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->d = d;
|
this->d = d;
|
||||||
@@ -144,9 +142,7 @@ static int cr_lib_load(int stage, char *path)
|
|||||||
if (d->init && d->init(stage)) {
|
if (d->init && d->init(stage)) {
|
||||||
pr_err("Failed in init(%d) of \"%s\"\n", stage, d->name);
|
pr_err("Failed in init(%d) of \"%s\"\n", stage, d->name);
|
||||||
list_del(&this->list);
|
list_del(&this->list);
|
||||||
xfree(this);
|
goto error_free;
|
||||||
dlclose(h);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -160,6 +156,14 @@ static int cr_lib_load(int stage, char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error_free:
|
||||||
|
xfree(this);
|
||||||
|
error_close:
|
||||||
|
dlclose(h);
|
||||||
|
if (allocated)
|
||||||
|
xfree(d);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cr_plugin_fini(int stage, int ret)
|
void cr_plugin_fini(int stage, int ret)
|
||||||
|
Reference in New Issue
Block a user