diff mbox series

[1/4] libtraceevent: close shared object in the error path of load_plugin()

Message ID 20240607160542.46152-2-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit 34ece90e09559089da0bfec1a1a03396fd507178
Headers show
Series libtraceevent: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 7, 2024, 4:05 p.m. UTC
The handle returned by dlopen() isn't close if an error occures
afterward. Call dlclose() in the error path.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 src/event-plugin.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/src/event-plugin.c b/src/event-plugin.c
index f42243f..7f94107 100644
--- a/src/event-plugin.c
+++ b/src/event-plugin.c
@@ -474,7 +474,7 @@  load_plugin(struct tep_handle *tep, const char *path,
 		while (options->name) {
 			ret = update_option(alias, options);
 			if (ret < 0)
-				goto out_free;
+				goto out_close;
 			options++;
 		}
 	}
@@ -483,13 +483,13 @@  load_plugin(struct tep_handle *tep, const char *path,
 	if (!func) {
 		tep_warning("could not find func '%s' in plugin '%s'\n%s\n",
 			    TEP_PLUGIN_LOADER_NAME, plugin, dlerror());
-		goto out_free;
+		goto out_close;
 	}
 
 	list = malloc(sizeof(*list));
 	if (!list) {
 		tep_warning("could not allocate plugin memory\n");
-		goto out_free;
+		goto out_close;
 	}
 
 	list->next = *plugin_list;
@@ -501,6 +501,8 @@  load_plugin(struct tep_handle *tep, const char *path,
 	func(tep);
 	return;
 
+out_close:
+	dlclose(handle);
  out_free:
 	free(plugin);
 }