summaryrefslogtreecommitdiff
path: root/tools/perf/util
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2023-04-27 16:05:01 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-05-02 08:36:14 -0300
commit7586d11d36fad5e6a28736be7ac8f9495e28289a (patch)
tree9b55c0336a6e3589dfd240f59292ba94c542b9c5 /tools/perf/util
parentb9f82b5c63bf5390da19e879275a792a959a8dac (diff)
perf list: Fix memory leaks in print_tracepoint_events()
It should free entries (not only the array) filled by scandirat() after use. Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20230427230502.1526136-1-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/print-events.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 386b1ab0b60e..f5b2ea0c4fa1 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -83,11 +83,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus
if (sys_dirent->d_type != DT_DIR ||
!strcmp(sys_dirent->d_name, ".") ||
!strcmp(sys_dirent->d_name, ".."))
- continue;
+ goto next_sys;
dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH);
if (dir_fd < 0)
- continue;
+ goto next_sys;
evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort);
for (int j = 0; j < evt_items; j++) {
@@ -98,12 +98,12 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus
if (evt_dirent->d_type != DT_DIR ||
!strcmp(evt_dirent->d_name, ".") ||
!strcmp(evt_dirent->d_name, ".."))
- continue;
+ goto next_evt;
snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name);
evt_fd = openat(dir_fd, evt_path, O_RDONLY);
if (evt_fd < 0)
- continue;
+ goto next_evt;
close(evt_fd);
snprintf(evt_path, MAXPATHLEN, "%s:%s",
@@ -119,9 +119,13 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus
/*desc=*/NULL,
/*long_desc=*/NULL,
/*encoding_desc=*/NULL);
+next_evt:
+ free(evt_namelist[j]);
}
close(dir_fd);
free(evt_namelist);
+next_sys:
+ free(sys_namelist[i]);
}
free(sys_namelist);