From 34ece90e09559089da0bfec1a1a03396fd507178 Mon Sep 17 00:00:00 2001
From: Jerome Marchand <jmarchan@redhat.com>
Date: Fri, 7 Jun 2024 18:05:39 +0200
Subject: [PATCH 3/7] libtraceevent: Close shared object in the error path of
load_plugin()
The handle returned by dlopen() isn't close if an error occurs
afterward. Call dlclose() in the error path.
Fixes a RESOURCE_LEAK error (CWE-772)
Link: https://lore.kernel.org/linux-trace-devel/20240607160542.46152-2-jmarchan@redhat.com
Fixes: 7e95ebdbbc3a9 ("tools lib traceevent: Add plugin support")
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
src/event-plugin.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
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);
}
--
2.45.2