|
Jerome Marchand |
7cf8e2 |
From 34ece90e09559089da0bfec1a1a03396fd507178 Mon Sep 17 00:00:00 2001
|
|
Jerome Marchand |
7cf8e2 |
From: Jerome Marchand <jmarchan@redhat.com>
|
|
Jerome Marchand |
7cf8e2 |
Date: Fri, 7 Jun 2024 18:05:39 +0200
|
|
Jerome Marchand |
7cf8e2 |
Subject: [PATCH 3/7] libtraceevent: Close shared object in the error path of
|
|
Jerome Marchand |
7cf8e2 |
load_plugin()
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
The handle returned by dlopen() isn't close if an error occurs
|
|
Jerome Marchand |
7cf8e2 |
afterward. Call dlclose() in the error path.
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
Fixes a RESOURCE_LEAK error (CWE-772)
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
Link: https://lore.kernel.org/linux-trace-devel/20240607160542.46152-2-jmarchan@redhat.com
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
Fixes: 7e95ebdbbc3a9 ("tools lib traceevent: Add plugin support")
|
|
Jerome Marchand |
7cf8e2 |
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
|
|
Jerome Marchand |
7cf8e2 |
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
|
|
Jerome Marchand |
7cf8e2 |
---
|
|
Jerome Marchand |
7cf8e2 |
src/event-plugin.c | 8 +++++---
|
|
Jerome Marchand |
7cf8e2 |
1 file changed, 5 insertions(+), 3 deletions(-)
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
diff --git a/src/event-plugin.c b/src/event-plugin.c
|
|
Jerome Marchand |
7cf8e2 |
index f42243f..7f94107 100644
|
|
Jerome Marchand |
7cf8e2 |
--- a/src/event-plugin.c
|
|
Jerome Marchand |
7cf8e2 |
+++ b/src/event-plugin.c
|
|
Jerome Marchand |
7cf8e2 |
@@ -474,7 +474,7 @@ load_plugin(struct tep_handle *tep, const char *path,
|
|
Jerome Marchand |
7cf8e2 |
while (options->name) {
|
|
Jerome Marchand |
7cf8e2 |
ret = update_option(alias, options);
|
|
Jerome Marchand |
7cf8e2 |
if (ret < 0)
|
|
Jerome Marchand |
7cf8e2 |
- goto out_free;
|
|
Jerome Marchand |
7cf8e2 |
+ goto out_close;
|
|
Jerome Marchand |
7cf8e2 |
options++;
|
|
Jerome Marchand |
7cf8e2 |
}
|
|
Jerome Marchand |
7cf8e2 |
}
|
|
Jerome Marchand |
7cf8e2 |
@@ -483,13 +483,13 @@ load_plugin(struct tep_handle *tep, const char *path,
|
|
Jerome Marchand |
7cf8e2 |
if (!func) {
|
|
Jerome Marchand |
7cf8e2 |
tep_warning("could not find func '%s' in plugin '%s'\n%s\n",
|
|
Jerome Marchand |
7cf8e2 |
TEP_PLUGIN_LOADER_NAME, plugin, dlerror());
|
|
Jerome Marchand |
7cf8e2 |
- goto out_free;
|
|
Jerome Marchand |
7cf8e2 |
+ goto out_close;
|
|
Jerome Marchand |
7cf8e2 |
}
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
list = malloc(sizeof(*list));
|
|
Jerome Marchand |
7cf8e2 |
if (!list) {
|
|
Jerome Marchand |
7cf8e2 |
tep_warning("could not allocate plugin memory\n");
|
|
Jerome Marchand |
7cf8e2 |
- goto out_free;
|
|
Jerome Marchand |
7cf8e2 |
+ goto out_close;
|
|
Jerome Marchand |
7cf8e2 |
}
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
list->next = *plugin_list;
|
|
Jerome Marchand |
7cf8e2 |
@@ -501,6 +501,8 @@ load_plugin(struct tep_handle *tep, const char *path,
|
|
Jerome Marchand |
7cf8e2 |
func(tep);
|
|
Jerome Marchand |
7cf8e2 |
return;
|
|
Jerome Marchand |
7cf8e2 |
|
|
Jerome Marchand |
7cf8e2 |
+out_close:
|
|
Jerome Marchand |
7cf8e2 |
+ dlclose(handle);
|
|
Jerome Marchand |
7cf8e2 |
out_free:
|
|
Jerome Marchand |
7cf8e2 |
free(plugin);
|
|
Jerome Marchand |
7cf8e2 |
}
|
|
Jerome Marchand |
7cf8e2 |
--
|
|
Jerome Marchand |
7cf8e2 |
2.45.2
|
|
Jerome Marchand |
7cf8e2 |
|