diff mbox series

[35/38] trace-cmd: move the initialization of found_pid at the beginning of stop_trace_connect()

Message ID 20240605134054.2626953-36-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit a4968a16b773268b232dd58fa7d2718d001e7b86
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
In stop_trace_connect(), trace_fields.found_pid is used in the error
path before it has been initialized. Move the initialization at the
beginning of the function.

Fixes a UNINIT error (CWE-457)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 tracecmd/trace-vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c
index f78f1d83..960ed5d5 100644
--- a/tracecmd/trace-vm.c
+++ b/tracecmd/trace-vm.c
@@ -280,6 +280,7 @@  static int stop_trace_connect(struct tracefs_instance *open_instance)
 
 	tep = tracefs_local_events_system(NULL, systems);
 
+	trace_fields.found_pid = -1;
 	trace_fields.sched_waking = tep_find_event_by_name(tep, "sched", "sched_waking");
 	if (!trace_fields.sched_waking)
 		goto out;
@@ -295,7 +296,6 @@  static int stop_trace_connect(struct tracefs_instance *open_instance)
 	if (!trace_fields.sched_next)
 		goto out;
 
-	trace_fields.found_pid = -1;
 	trace_fields.pids = NULL;
 	add_pid(&trace_fields.pids, getpid());
 	tracefs_iterate_raw_events(tep, open_instance, NULL, 0, callback, &trace_fields);