perf trace: Free thread_trace->files table

The fd->pathname table that is kept in 'struct thread_trace' and thus in
thread->priv must be freed when a thread is deleted.

This was also detected using -fsanitize=address.
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/20230719202951.534582-6-acme@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7962ef13
...@@ -1296,6 +1296,8 @@ static struct thread_trace *thread_trace__new(void) ...@@ -1296,6 +1296,8 @@ static struct thread_trace *thread_trace__new(void)
return ttrace; return ttrace;
} }
static void thread_trace__free_files(struct thread_trace *ttrace);
static void thread_trace__delete(void *pttrace) static void thread_trace__delete(void *pttrace)
{ {
struct thread_trace *ttrace = pttrace; struct thread_trace *ttrace = pttrace;
...@@ -1305,6 +1307,7 @@ static void thread_trace__delete(void *pttrace) ...@@ -1305,6 +1307,7 @@ static void thread_trace__delete(void *pttrace)
intlist__delete(ttrace->syscall_stats); intlist__delete(ttrace->syscall_stats);
ttrace->syscall_stats = NULL; ttrace->syscall_stats = NULL;
thread_trace__free_files(ttrace);
zfree(&ttrace->entry_str); zfree(&ttrace->entry_str);
free(ttrace); free(ttrace);
} }
...@@ -1346,6 +1349,17 @@ void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg, ...@@ -1346,6 +1349,17 @@ void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg,
static const size_t trace__entry_str_size = 2048; 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) {
struct file *file = ttrace->files.table + i;
zfree(&file->pathname);
}
zfree(&ttrace->files.table);
ttrace->files.max = -1;
}
static struct file *thread_trace__files_entry(struct thread_trace *ttrace, int fd) static struct file *thread_trace__files_entry(struct thread_trace *ttrace, int fd)
{ {
if (fd < 0) if (fd < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment