From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v8 7/9] trace-cmd library: Avoid memory leak when setting trace clock
Date: Wed, 26 Jan 2022 11:51:52 +0200 [thread overview]
Message-ID: <20220126095154.570700-8-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20220126095154.570700-1-tz.stoyanov@gmail.com>
The API for setting a trace clock to a input handle did not check if the
clock is already set:
tracecmd_set_out_clock()
This could cause a memory leak, if the clock is already set - the old
clock string is overwritten. The old clock should be freed before
setting the new one.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-output.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index b54c68fe..c1ba8a52 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -227,8 +227,10 @@ void tracecmd_set_quiet(struct tracecmd_output *handle, bool set_quiet)
void tracecmd_set_out_clock(struct tracecmd_output *handle, const char *clock)
{
- if (handle && clock)
+ if (handle && clock) {
+ free(handle->trace_clock);
handle->trace_clock = strdup(clock);
+ }
}
/**
--
2.34.1
next prev parent reply other threads:[~2022-01-26 9:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 9:51 [PATCH v8 0/9] *trace-cmd convert Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` [PATCH v8 1/9] trace-cmd library: Use output handler when copying data from input file Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` [PATCH v8 2/9] trace-cmd library: Handle version 7 files when copying headers between files Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` [PATCH v8 3/9] trace-cmd library: Copy CPU count between trace files Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` [PATCH v8 4/9] trace-cmd library: New API to copy buffer description " Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` [PATCH v8 5/9] trace-cmd library: New API to copy options " Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` [PATCH v8 6/9] trace-cmd library: New API to copy trace data " Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` Tzvetomir Stoyanov (VMware) [this message]
2022-01-26 9:51 ` [PATCH v8 8/9] trace-cmd library: Extend tracecmd_copy() API Tzvetomir Stoyanov (VMware)
2022-01-26 9:51 ` [PATCH v8 9/9] trace-cmd: Add new subcommand "convert" 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=20220126095154.570700-8-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).