The handle returned by dlopen() isn't closes if something else fails afterwards. Call dlclose in the error path to fix that. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx> --- lib/trace-cmd/trace-plugin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/trace-cmd/trace-plugin.c b/lib/trace-cmd/trace-plugin.c index 127771ea..0d477dff 100644 --- a/lib/trace-cmd/trace-plugin.c +++ b/lib/trace-cmd/trace-plugin.c @@ -126,13 +126,13 @@ load_plugin(struct trace_plugin_context *trace, const char *path, if (!func) { tracecmd_warning("could not find func '%s' in plugin '%s'\n%s", TRACECMD_PLUGIN_LOADER_NAME, plugin, dlerror()); - goto out_free; + goto out_close; } list = malloc(sizeof(*list)); if (!list) { tracecmd_warning("could not allocate plugin memory"); - goto out_free; + goto out_close; } list->next = *plugin_list; @@ -143,7 +143,9 @@ load_plugin(struct trace_plugin_context *trace, const char *path, tracecmd_info("registering plugin: %s", plugin); func(trace); return; - + +out_close: + dlclose(handle); out_free: free(plugin); } -- 2.44.0