From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 2/3] trace-cmd: Fix double free error when triggers are configured on multiple events
Date: Wed, 25 Mar 2020 16:08:28 +0200 [thread overview]
Message-ID: <20200325140829.184651-3-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20200325140829.184651-1-tz.stoyanov@gmail.com>
When using trace-cmd "-e sched:* -R ..." command to set triggers to the all events
of given subsystem, trace-cmd fails with a double free error.
The problem is in create_event() function, where the config is expanded to the all
events. The same "event->trigger" pointer is copied to all events. Later, when the
trigger is applied, the update_event() frees this pointer multiple times.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
tracecmd/trace-record.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index ec3bcae9..7dbf599a 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -2702,7 +2702,8 @@ create_event(struct buffer_instance *instance, char *path, struct event_list *ol
else
free(p);
- if (event->trigger) {
+ if (old_event->trigger) {
+ event->trigger = strdup(old_event->trigger);
ret = asprintf(&p, "%s/trigger", path_dirname);
if (ret < 0)
die("Failed to allocate trigger path for %s", path);
@@ -2883,6 +2884,7 @@ static void expand_event_instance(struct buffer_instance *instance)
event = compressed_list;
compressed_list = event->next;
expand_event(instance, event);
+ free(event->trigger);
free(event);
}
}
--
2.25.1
next prev parent reply other threads:[~2020-03-25 14:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-25 14:08 [PATCH 0/3] Fix applying triggers to multiple events Tzvetomir Stoyanov (VMware)
2020-03-25 14:08 ` [PATCH 1/3] trace-cmd: Fix check for trigger file in create_event() Tzvetomir Stoyanov (VMware)
2020-03-25 14:08 ` Tzvetomir Stoyanov (VMware) [this message]
2020-03-25 14:08 ` [PATCH 3/3] trace-cmd: Fix setting triggers to all events from given system Tzvetomir Stoyanov (VMware)
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=20200325140829.184651-3-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.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).