[PATCH 2/3] trace-cmd: Have tracecmd_tsync_free() free even with no context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux