Skip to content

perf python: Fix python extension bugs from v19 review

Ian Rogers linux-perf-users lkml sashiko-reviews 3 versions – Applied

Status from this message: Applied to perf-tools-next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest15 patches 3 repliesApplied
  2. v216 patches 4 repliesSuperseded
  3. v113 patches 0 repliesSuperseded

Changes in v3 from the cover letter

- Addressed review feedback from Namhyung Kim and Sashiko AI:
- Dropped "perf data: Fix directory file descriptor leak in perf_data__switch" to avoid Use-After-Free during directory mode file rotation.
- Added list == NULL check in pyrf_counts_values_set_values to safely handle attribute deletion (del obj.values).
- Preserved errno before calling intlist__delete(skiplist) in cmd_test error path to prevent clobbering the return error code.
- Added CHECK_INITIALIZED to pyrf_pmu__repr to prevent NULL pointer dereferences on uninitialized PMU objects.
- Fixed duplicate patch title from v2.

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/15perf script: Fix metric_evlist leak in script_find_metricstools/perf/builtin-script.c+1 -10 replies
2/15perf stat: Fix evsel_list leak in cmd_stattools/perf/builtin-stat.c+6 -30 replies
3/15perf tools: Fix sb_evlist leaks in top and recordtools/perf/builtin-record.c tools/perf/builtin-top.c+4 -00 replies
4/15perf python: Fix memory leak in pyrf_evlist__get_pollfdtools/perf/util/python.c+3 -00 replies
5/15perf synthetic-events: Fix uninitialized pthread_jointools/perf/util/synthetic-events.c+2 -20 replies
6/15perf test: Fix skiplist leak in cmd_testtools/perf/tests/builtin-test.c+7 -20 replies
7/15perf python: Check counts_values size in set_valuestools/perf/util/python.c+30 -80 replies
8/15perf python: Validate CPU and thread maps in pyrf_evsel__opentools/perf/util/python.c+12 -20 replies
9/15perf python: Validate attribute setters in pyrf_evseltools/perf/util/python.c+77 -120 replies
10/15perf python: Zero initialize perf_data in pyrf_data__inittools/perf/util/python.c+2 -10 replies
11/15perf python: Add thread and PMU uninitialized checkstools/perf/util/python.c+8 -02 replies
12/15perf python: Fix MetricGroup return type in perf.pyitools/perf/python/perf.pyi+2 -20 replies
13/15perf python: Fix count_values memory leak in pyrf_evsel__readtools/perf/util/python.c+4 -50 replies
14/15perf python: Fix memory leak in pyrf__metrics_cbtools/perf/util/python.c+2 -00 replies
15/15perf synthetic-events: Fix divide by zero in perf_event__synthesize_threadstools/perf/util/synthetic-events.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 00/15] perf python: Fix python extension bugs from v19 review

Phase 1 of splitting the v19 review patches into smaller fixes. These patches address issues identified in the python extension during the review of the v19 script porting series, as well as fixing several pre-existing bugs and leaks.

v3:
- Addressed review feedback from Namhyung Kim and Sashiko AI:
- Dropped "perf data: Fix directory file descriptor leak in perf_data__switch" to avoid Use-After-Free during directory mode file rotation.
- Added list == NULL check in pyrf_counts_values_set_values to safely handle attribute deletion (del obj.values).
- Preserved errno before calling intlist__delete(skiplist) in cmd_test error path to prevent clobbering the return error code.
- Added CHECK_INITIALIZED to pyrf_pmu__repr to prevent NULL pointer dereferences on uninitialized PMU objects.
- Fixed duplicate patch title from v2.

v2:
- Addressed sashiko review feedback:
- Fixed 64-bit casting for counts_values by using T_ULONGLONG and PyLong_FromUnsignedLongLong.
- Replaced strict Py_TYPE checks with PyObject_TypeCheck for thread/cpu maps.
- Fixed a missing CHECK_INITIALIZED for pyrf_thread__get_cpu, pyrf_pmu__name, pyrf_pmu__events.
- Included <string.h> where memset was used.
- Fixed line splitting formatting on PyObject_New in pyrf_evsel__read.
- Added fixes for memory leaks and issues discovered during review:
- Fix memory leak of key and value in pyrf__metrics_cb
- Fix count_values memory leak in pyrf_evsel__read
- Fix sb_evlist leaks in both top and record paths.
- Fix potential divide by zero in perf_event__synthesize_threads

v1:
- Decomposed the single large "Fix python extension bugs" patch into 13 individual fixes.
- Added Fixes: tags for issues that date back to earlier commits.
- Addressed checkpatch warnings (line lengths, Signed-off-by, etc).

Ian Rogers (15):
perf script: Fix metric_evlist leak in script_find_metrics perf stat: Fix evsel_list leak in cmd_stat
perf tools: Fix sb_evlist leaks in top and record perf python: Fix memory leak in pyrf_evlist__get_pollfd perf synthetic-events: Fix uninitialized pthread_join perf test: Fix skiplist leak in cmd_test
perf python: Check counts_values size in set_values perf python: Validate CPU and thread maps in pyrf_evsel__open perf python: Validate attribute setters in pyrf_evsel perf python: Zero initialize perf_data in pyrf_data__init perf python: Add thread and PMU uninitialized checks perf python: Fix MetricGroup return type in perf.pyi perf python: Fix count_values memory leak in pyrf_evsel__read perf python: Fix memory leak in pyrf__metrics_cb perf synthetic-events: Fix divide by zero in
perf_event__synthesize_threads

 tools/perf/builtin-record.c        |   2 +
 tools/perf/builtin-script.c        |   2 +-
 tools/perf/builtin-stat.c          |   9 +-
 tools/perf/builtin-top.c           |   2 +
 tools/perf/python/perf.pyi         |   4 +-
 tools/perf/tests/builtin-test.c    |   9 +-
 tools/perf/util/python.c           | 166 ++++++++++++++++++++++++-----
 tools/perf/util/synthetic-events.c |   6 +-
 8 files changed, 161 insertions(+), 39 deletions(-)
Signature · 1 line
2.55.0.679.g6767b8d81c-goog