summaryrefslogtreecommitdiff
path: root/tools/perf/util/python.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-08-09 00:14:53 -0700
committerNamhyung Kim <namhyung@kernel.org>2026-08-09 22:02:41 -0700
commit1ec13016ba36f1bf7dc61e054068fe00f2f628c7 (patch)
treedd8a4b5565cf9408857254c404bbd523df553f57 /tools/perf/util/python.c
parentcb45ede21d02cc85de18ce6b60a51a7449f4179b (diff)
perf python: Fix memory leak in pyrf__metrics_cb
In pyrf__metrics_cb, PyDict_SetItem does not steal the reference of the key and value, so they need to be decref'ed after successful insertion to avoid memory leaks. Fixes: 47b3e95728eb ("perf python: Add metrics function") 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.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 7bb7942e9d21..d8a842621cda 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -3575,6 +3575,8 @@ static int pyrf__metrics_cb(const struct pmu_metric *pm,
Py_XDECREF(dict);
return -ENOMEM;
}
+ Py_DECREF(key);
+ Py_DECREF(value);
if (!add_to_dict(dict, "MetricName", pm->metric_name) ||
!add_to_dict(dict, "PMU", pm->pmu) ||