perf trace: Free the files.max entry in files->table
authorIan Rogers <irogers@google.com>
Tue, 1 Apr 2025 20:27:15 +0000 (13:27 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 8 May 2025 14:49:40 +0000 (11:49 -0300)
The files.max is the maximum valid fd in the files array and so
freeing the values needs to be inclusive of the max value.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250401202715.3493567-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c

index 809b4d5b0a8a4ddcba0e3494e701e789dfd72262..c39b7f8ff84627e35231ecd67a13e3eae250cd86 100644 (file)
@@ -1653,7 +1653,7 @@ static const size_t trace__entry_str_size = 2048;
 
 static void thread_trace__free_files(struct thread_trace *ttrace)
 {
-       for (int i = 0; i < ttrace->files.max; ++i) {
+       for (int i = 0; i <= ttrace->files.max; ++i) {
                struct file *file = ttrace->files.table + i;
                zfree(&file->pathname);
        }
@@ -1699,6 +1699,7 @@ static int trace__set_fd_pathname(struct thread *thread, int fd, const char *pat
 
        if (file != NULL) {
                struct stat st;
+
                if (stat(pathname, &st) == 0)
                        file->dev_maj = major(st.st_rdev);
                file->pathname = strdup(pathname);