aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/python.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <[email protected]>2025-03-12 20:31:39 +0000
committerNamhyung Kim <[email protected]>2025-03-18 23:08:29 +0000
commit3de5a2bf5b4847f7a59a184568f969f8fe05d57f (patch)
treeecf453076138fd54ab718f30be7a5aa52716fcfa /tools/perf/util/python.c
parentperf python tracepoint.py: Change the COMM using setproctitle if available (diff)
downloadkernel-3de5a2bf5b4847f7a59a184568f969f8fe05d57f.tar.gz
kernel-3de5a2bf5b4847f7a59a184568f969f8fe05d57f.zip
perf python: Decrement the refcount of just created event on failure
To avoid a leak if we have the python object but then something happens and we need to return the operation, decrement the offset of the newly created object. Fixes: 377f698db12150a1 ("perf python: Add struct evsel into struct pyrf_event") Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Reviewed-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
Diffstat (limited to 'tools/perf/util/python.c')
-rw-r--r--tools/perf/util/python.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index f9491b669976..31a877a8eb8f 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1012,6 +1012,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
evsel = evlist__event2evsel(evlist, event);
if (!evsel) {
+ Py_DECREF(pyevent);
Py_INCREF(Py_None);
return Py_None;
}
@@ -1023,9 +1024,12 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
/* Consume the even only after we parsed it out. */
perf_mmap__consume(&md->core);
- if (err)
+ if (err) {
+ Py_DECREF(pyevent);
return PyErr_Format(PyExc_OSError,
"perf: can't parse sample, err=%d", err);
+ }
+
return pyevent;
}
end: