diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2025-03-12 17:31:39 -0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-04-10 14:37:34 +0200 |
| commit | 6bc0c3e7582c67891788fc16c6c21563e977f685 (patch) | |
| tree | f1e6f72f1f95100695933267e512690bbad66b87 /tools | |
| parent | b8e2e2cfa319b8f6f1540a82f74be91f69a28a1d (diff) | |
| download | linux-6bc0c3e7582c67891788fc16c6c21563e977f685.tar.gz linux-6bc0c3e7582c67891788fc16c6c21563e977f685.tar.bz2 linux-6bc0c3e7582c67891788fc16c6c21563e977f685.zip | |
perf python: Decrement the refcount of just created event on failure
[ Upstream commit 3de5a2bf5b4847f7a59a184568f969f8fe05d57f ]
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 <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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/util/python.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 8753c9d3670a..47c43b9c72fe 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1170,6 +1170,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; } @@ -1181,9 +1182,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: |
