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: 377f698db1 ("perf python: Add struct evsel into struct pyrf_event")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250312203141.285263-5-acme@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
committed by
Namhyung Kim
parent
a570da2148
commit
3de5a2bf5b
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user