mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-30 05:42:46 +01:00
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: 739621f657 ("perf python: Add evsel read method")
Signed-off-by: Ian Rogers <[email protected]>
Signed-off-by: Namhyung Kim <[email protected]>
This commit is contained in:
1 parent
b9514a9a13
commit
cb45ede21d
1 file changed
+4
-5
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user