[PATCH v4 01/23] perf machine: Fix NULL deref on allocation failure in __machine__findnew_thread()
From: Ian Rogers
Date: Fri Nov 13 2026 - 12:39:40 EST
When threads__findnew() fails to allocate a struct thread (or fails to
insert it into the shard hashmap and no concurrent thread inserted the
tid), it returns NULL with *created == false.
In __machine__findnew_thread(), the !created branch unconditionally
passed th to machine__update_thread_pid(), which immediately
dereferenced NULL via thread__pid(th) instead of propagating NULL to the
caller.
Guard the machine__update_thread_pid() call with 'else if (th)' so
allocation failure returns NULL cleanly.
Fixes: d436f90a64f3 ("perf machine: Move machine's threads into its own abstraction")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/machine.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 5eb5efa4eb90..dc0aaac992f9 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -568,8 +568,9 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
thread__put(th);
return NULL;
}
- } else
+ } else if (th) {
machine__update_thread_pid(machine, th, pid);
+ }
return th;
}
--
2.56.1.703.gf848ed807c-goog