From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: [PATCH v2 2/4] perf timechart: Fix memory leaks during record
Date: Fri, 5 Jun 2026 16:51:29 -0700 [thread overview]
Message-ID: <20260605235131.2440270-3-namhyung@kernel.org> (raw)
In-Reply-To: <20260605235131.2440270-1-namhyung@kernel.org>
The command line options can be passed without copy as their lifetime is
limited within the same function.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-timechart.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 27d17268395ed760..a73f0ab22fd64241 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1834,6 +1834,7 @@ static int timechart__io_record(int argc, const char **argv, const char *output_
"syscalls:sys_exit_select",
};
unsigned int poll_events_nr = ARRAY_SIZE(poll_events);
+ int ret;
rec_argc = common_args_nr +
disk_events_nr * 4 +
@@ -1852,7 +1853,7 @@ static int timechart__io_record(int argc, const char **argv, const char *output_
p = rec_argv;
for (i = 0; i < common_args_nr; i++)
- *p++ = strdup(common_args[i]);
+ *p++ = common_args[i];
for (i = 0; i < disk_events_nr; i++) {
if (!is_valid_tracepoint(disk_events[i])) {
@@ -1861,7 +1862,7 @@ static int timechart__io_record(int argc, const char **argv, const char *output_
}
*p++ = "-e";
- *p++ = strdup(disk_events[i]);
+ *p++ = disk_events[i];
*p++ = "--filter";
*p++ = filter;
}
@@ -1872,7 +1873,7 @@ static int timechart__io_record(int argc, const char **argv, const char *output_
}
*p++ = "-e";
- *p++ = strdup(net_events[i]);
+ *p++ = net_events[i];
*p++ = "--filter";
*p++ = filter;
}
@@ -1883,7 +1884,7 @@ static int timechart__io_record(int argc, const char **argv, const char *output_
}
*p++ = "-e";
- *p++ = strdup(poll_events[i]);
+ *p++ = poll_events[i];
*p++ = "--filter";
*p++ = filter;
}
@@ -1891,7 +1892,11 @@ static int timechart__io_record(int argc, const char **argv, const char *output_
for (i = 0; i < (unsigned int)argc; i++)
*p++ = argv[i];
- return cmd_record(rec_argc, rec_argv);
+ ret = cmd_record(rec_argc, rec_argv);
+
+ free(rec_argv);
+ free(filter);
+ return ret;
}
@@ -1902,6 +1907,7 @@ static int timechart__record(struct timechart *tchart, int argc, const char **ar
const char **rec_argv;
const char **p;
unsigned int record_elems;
+ int ret;
const char * const common_args[] = {
"record", "-a", "-R", "-c", "1", "-o", output_data,
@@ -1966,24 +1972,27 @@ static int timechart__record(struct timechart *tchart, int argc, const char **ar
p = rec_argv;
for (i = 0; i < common_args_nr; i++)
- *p++ = strdup(common_args[i]);
+ *p++ = common_args[i];
for (i = 0; i < backtrace_args_no; i++)
- *p++ = strdup(backtrace_args[i]);
+ *p++ = backtrace_args[i];
for (i = 0; i < tasks_args_nr; i++)
- *p++ = strdup(tasks_args[i]);
+ *p++ = tasks_args[i];
for (i = 0; i < power_args_nr; i++)
- *p++ = strdup(power_args[i]);
+ *p++ = power_args[i];
for (i = 0; i < old_power_args_nr; i++)
- *p++ = strdup(old_power_args[i]);
+ *p++ = old_power_args[i];
for (j = 0; j < (unsigned int)argc; j++)
*p++ = argv[j];
- return cmd_record(rec_argc, rec_argv);
+ ret = cmd_record(rec_argc, rec_argv);
+
+ free(rec_argv);
+ return ret;
}
static int
--
2.54.0.1032.g2f8565e1d1-goog
next prev parent reply other threads:[~2026-06-05 23:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 23:51 [PATCH v2 0/4] perf timechart: Fix memory leaks Namhyung Kim
2026-06-05 23:51 ` [PATCH v2 1/4] perf timechart: Release event samples at the end Namhyung Kim
2026-06-06 0:05 ` sashiko-bot
2026-06-05 23:51 ` Namhyung Kim [this message]
2026-06-05 23:51 ` [PATCH v2 3/4] perf timechart: Fix memory leaks in draw_wakeups() Namhyung Kim
2026-06-05 23:51 ` [PATCH v2 4/4] perf test: Update perf timechart test Namhyung Kim
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=20260605235131.2440270-3-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/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