From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Subject: [PATCH 2/3] trace-cmd: Have tracecmd_tsync_free() free even with no context
Date: Wed, 31 Mar 2021 19:06:12 -0400 [thread overview]
Message-ID: <20210331230728.211232789@goodmis.org> (raw)
In-Reply-To: 20210331230610.035418770@goodmis.org
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
tracecmd_tsync_free() incorrectly exits the function if the tsync has no
context. But it may still need to free up the resources in that case. Do
not leak memory if the context failed to be created.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
lib/trace-cmd/trace-timesync.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index 4ed283eb1fb8..24984fb17dab 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -513,25 +513,28 @@ void tracecmd_tsync_free(struct tracecmd_time_sync *tsync)
struct clock_sync_context *tsync_context;
struct tsync_proto *proto;
- if (!tsync || !tsync->context)
+ if (!tsync)
return;
+
tsync_context = (struct clock_sync_context *)tsync->context;
proto = tsync_proto_find(tsync->proto_name);
if (proto && proto->clock_sync_free)
proto->clock_sync_free(tsync);
- clock_synch_delete_instance(tsync_context->instance);
- tsync_context->instance = NULL;
-
- free(tsync_context->sync_ts);
- free(tsync_context->sync_offsets);
- free(tsync_context->sync_scalings);
- tsync_context->sync_ts = NULL;
- tsync_context->sync_offsets = NULL;
- tsync_context->sync_scalings = NULL;
- tsync_context->sync_count = 0;
- tsync_context->sync_size = 0;
+ if (tsync_context) {
+ clock_synch_delete_instance(tsync_context->instance);
+ tsync_context->instance = NULL;
+
+ free(tsync_context->sync_ts);
+ free(tsync_context->sync_offsets);
+ free(tsync_context->sync_scalings);
+ tsync_context->sync_ts = NULL;
+ tsync_context->sync_offsets = NULL;
+ tsync_context->sync_scalings = NULL;
+ tsync_context->sync_count = 0;
+ tsync_context->sync_size = 0;
+ }
pthread_mutex_destroy(&tsync->lock);
pthread_cond_destroy(&tsync->cond);
pthread_barrier_destroy(&tsync->first_sync);
--
2.30.1
next prev parent reply other threads:[~2021-03-31 23:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-31 23:06 [PATCH 0/3] trace-cmd: Fix the memory mangement of trace-cmd agent Steven Rostedt
2021-03-31 23:06 ` [PATCH 1/3] trace-cmd agent: Clean up tsync_agent_thread() and tsync_host_thread() Steven Rostedt
2021-03-31 23:06 ` Steven Rostedt [this message]
2021-03-31 23:06 ` [PATCH 3/3] trace-cmd: Do not free tsync from thread 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=20210331230728.211232789@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.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).