]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf sched: Fix thread reference leak in latency_switch_event
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 4 Jun 2026 15:55:29 +0000 (12:55 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 4 Jun 2026 20:34:52 +0000 (17:34 -0300)
In latency_switch_event(), after acquiring thread references for
sched_out and sched_in via machine__findnew_thread(), the first
add_sched_out_event() failure path does 'return -1', bypassing the
out_put label that calls thread__put() on both references.

The second and third add_sched_out_event() failures correctly use
'goto out_put'.  Fix the first one to match.

Fixes: b91fc39f4ad7 ("perf machine: Protect the machine->threads with a rwlock")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-sched.c

index e7bd3f331cb8e889846929c996b8ca5b7dc7a38c..13b801496a01271e2048082ed92585747acf311c 100644 (file)
@@ -1180,7 +1180,7 @@ static int latency_switch_event(struct perf_sched *sched,
                }
        }
        if (add_sched_out_event(out_events, prev_state, timestamp))
-               return -1;
+               goto out_put;
 
        in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid);
        if (!in_events) {