From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Clark Williams <williams@redhat.com>,
Kate Carcia <kcarcia@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 5/6] perf trace: Free thread_trace->files table
Date: Wed, 19 Jul 2023 17:29:50 -0300 [thread overview]
Message-ID: <20230719202951.534582-6-acme@kernel.org> (raw)
In-Reply-To: <20230719202951.534582-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
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.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-trace.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 56651d666480cc16..7ece2521efb69182 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1296,6 +1296,8 @@ static struct thread_trace *thread_trace__new(void)
return ttrace;
}
+static void thread_trace__free_files(struct thread_trace *ttrace);
+
static void thread_trace__delete(void *pttrace)
{
struct thread_trace *ttrace = pttrace;
@@ -1305,6 +1307,7 @@ static void thread_trace__delete(void *pttrace)
intlist__delete(ttrace->syscall_stats);
ttrace->syscall_stats = NULL;
+ thread_trace__free_files(ttrace);
zfree(&ttrace->entry_str);
free(ttrace);
}
@@ -1346,6 +1349,17 @@ void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg,
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)
{
if (fd < 0)
--
2.41.0
next prev parent reply other threads:[~2023-07-19 20:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 1/6] perf evsel: Free evsel->filter on the destructor Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Arnaldo Carvalho de Melo
2023-07-19 22:31 ` Ian Rogers
2023-07-20 13:49 ` Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 3/6] perf trace: Register a thread priv destructor Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 4/6] perf trace: Really free the evsel->priv area Arnaldo Carvalho de Melo
2023-07-19 20:29 ` Arnaldo Carvalho de Melo [this message]
2023-07-19 20:29 ` [PATCH 6/6] MAINTAINERS: Add git information for perf-tools and perf-tools-next trees/branches Arnaldo Carvalho de Melo
2023-07-19 22:34 ` [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230719202951.534582-6-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kcarcia@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).