diff mbox series

[04/38] trace-cmd: call dlclose() in the error path of load_plugin()

Message ID 20240605134054.2626953-5-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit dcfce16d22fbd8cbd0e4c8de1742e56d03b527a4
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
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@redhat.com>
---
 lib/trace-cmd/trace-plugin.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

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);
 }