From: "Jerome Marchand" <jmarchan@redhat.com>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Jerome Marchand <jmarchan@redhat.com>
Subject: [PATCH 1/4] libtraceevent: close shared object in the error path of load_plugin()
Date: Fri, 7 Jun 2024 18:05:39 +0200 [thread overview]
Message-ID: <20240607160542.46152-2-jmarchan@redhat.com> (raw)
In-Reply-To: <20240607160542.46152-1-jmarchan@redhat.com>
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 --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.1
next prev parent reply other threads:[~2024-06-07 16:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-07 16:05 [PATCH 0/4] libtraceevent: fix misc issues found by static analysis Jerome Marchand
2024-06-07 16:05 ` Jerome Marchand [this message]
2024-06-07 16:05 ` [PATCH 2/4] libtraceevent: prevent a memory leak in process_fields() Jerome Marchand
2024-06-07 16:05 ` [PATCH 3/4] libtraceevent: prevent a memory leak in tep_plugin_add_option() Jerome Marchand
2024-06-07 16:05 ` [PATCH 4/4] libtraceevent: don't return a pointer to a local variable get_field_str() Jerome Marchand
2024-06-14 19:49 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240607160542.46152-2-jmarchan@redhat.com \
--to=jmarchan@redhat.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).