summaryrefslogtreecommitdiff
path: root/tools/perf/util/python.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-08-09 00:14:52 -0700
committerNamhyung Kim <namhyung@kernel.org>2026-08-09 22:02:41 -0700
commitcb45ede21d02cc85de18ce6b60a51a7449f4179b (patch)
tree6f7c031056f3bf403a5256d752df7c40f53fa2c7 /tools/perf/util/python.c
parentb9514a9a13fc782546df0fae7d5767dadd2094f5 (diff)
downloadlinux-stable-cb45ede21d02cc85de18ce6b60a51a7449f4179b.tar.gz
linux-stable-cb45ede21d02cc85de18ce6b60a51a7449f4179b.zip
perf python: Fix count_values memory leak in pyrf_evsel__read
In pyrf_evsel__read, if PyArg_ParseTuple fails, the allocated count_values is leaked. Move the allocation of count_values after the PyArg_ParseTuple call to prevent the memory leak. Fixes: 739621f65702 ("perf python: Add evsel read method") Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf/util/python.c')
-rw-r--r--tools/perf/util/python.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 36c5f4b0d0bb..7bb7942e9d21 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -2211,11 +2211,6 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel,
CHECK_INITIALIZED(evsel, "evsel");
- count_values = PyObject_New(struct pyrf_counts_values,
- &pyrf_counts_values__type);
- if (!count_values)
- return NULL;
-
if (!PyArg_ParseTuple(args, "ii", &cpu, &thread))
return NULL;
@@ -2234,6 +2229,10 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel,
if (evsel__ensure_counts(evsel))
return PyErr_NoMemory();
+ count_values = PyObject_New(struct pyrf_counts_values, &pyrf_counts_values__type);
+ if (!count_values)
+ return NULL;
+
/* Set up pointers to the old and newly read counter values. */
old_count = perf_counts(evsel->prev_raw_counts, cpu_idx, thread_idx);
new_count = perf_counts(evsel->counts, cpu_idx, thread_idx);