Re: [PATCH v3 11/15] perf python: Add thread and PMU uninitialized checks
| Newsgroups | org.kernel.vger.linux-perf-users |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The newly added `CHECK_INITIALIZED(ppmu->pmu, "pmu")` in `pyrf_pmu__events()` causes a Python object memory leak of `py_list` on the error path. -- --- Patch [11]: [PATCH v3 11/15] perf python: Add thread and PMU uninitialized checks --- commit a381b82bb0eb00b93be525bfa1c265b574c03a5a Author: Ian Rogers <[email protected]> perf python: Add thread and PMU uninitialized checks This commit adds CHECK_INITIALIZED guards to thread and PMU getters to prevent crashes when accessed before proper initialization. > diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c > index c70b151428f76..fe5afce173330 100644 > --- a/tools/perf/util/python.c > +++ b/tools/perf/util/python.c [ ... ] > @@ -1730,6 +1731,8 @@ static PyObject *pyrf_pmu__events(PyObject *self) > PyObject *py_list = PyList_New(0); > int ret; > > + CHECK_INITIALIZED(ppmu->pmu, "pmu"); > + > if (!py_list) > return NULL; [Severity: Medium] Does this code leak py_list if CHECK_INITIALIZED fails and returns early? Since py_list is allocated with PyList_New(0) just before the initialization check, it appears this Python object is left orphaned if the macro evaluates to true and forces an early return. Could the CHECK_INITIALIZED macro be moved to the beginning of pyrf_pmu__events() before the PyList_New(0) allocation to avoid this leak? -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11