[PATCH 1/2] perf kvm: Don't pass an ERR_PTR to perf_session__delete()
From: James Clark
Date: Wed Nov 25 2026 - 10:13:01 EST
If perf_session__new() fails, kvm->session is left holding the ERR_PTR
value when jumping to the out label. The cleanup then calls
perf_session__delete() on it, which only checks for NULL and goes on to
dereference the error pointer.
Fix it by clearing kvm->session before the goto. builtin-top.c and
builtin-lock.c already follow the exact same pattern.
Fixes: 6ef81c55a2b6 ("perf session: Return error code for perf_session__new() function on failure")
Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
tools/perf/builtin-kvm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 67eb3f667c99..785b761fb951 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1926,6 +1926,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
kvm->session = perf_session__new(&data, &kvm->tool);
if (IS_ERR(kvm->session)) {
err = PTR_ERR(kvm->session);
+ kvm->session = NULL;
goto out;
}
kvm->session->evlist = kvm->evlist;
--
2.43.0