linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracecmd library: Unlock records in tracecmd_iterate_events()
@ 2023-06-06 18:52 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2023-06-06 18:52 UTC (permalink / raw)
  To: Linux Trace Devel

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The tracecmd_iterate_events() and tracecmd_iterate_events_multi() uses
tracecmd_peek_data() to look at the next record. But when this is done,
the record is "cached" and "locked" in the handle. Which means they can
not be freed.

At the end of the iterators, make sure to read the data to unlock them,
and then free them.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 3dd13ce45fef..ced016a221ca 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -2818,8 +2818,13 @@ int tracecmd_iterate_events(struct tracecmd_input *handle,
 		}
 	} while (next_cpu >= 0 && ret >= 0);
 
-	for (cpu = 0; cpu < handle->max_cpu; cpu++)
-		tracecmd_free_record(records[cpu]);
+	/* Need to unlock and free the records */
+	for (cpu = 0; cpu < handle->max_cpu; cpu++) {
+		if (!records[cpu])
+			continue;
+		record = tracecmd_read_data(handle, cpu);
+		tracecmd_free_record(record);
+	}
 
 	free(records);
 
@@ -2909,6 +2914,19 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles,
 
 	} while (next_cpu >= 0 && ret >= 0);
 
+	/* Unlock and free the records */
+	for (cpu = 0; cpu < all_cpus; cpu++) {
+		int local_cpu;
+
+		if (!records[cpu].record)
+			continue;
+
+		handle = records[cpu].handle;
+		local_cpu = cpu - handle->start_cpu;
+		record = tracecmd_read_data(handle, local_cpu);
+		tracecmd_free_record(record);
+	}
+
 	/*
 	 * The records array contains only records that were taken via
 	 * tracecmd_peek_data(), and do not need to be freed.
-- 
2.39.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-06 18:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06 18:52 [PATCH] tracecmd library: Unlock records in tracecmd_iterate_events() Steven Rostedt

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).