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 v3 5/6] perf kvm: Fix a memory leak in the usage string
Date: Wed, 1 Jul 2026 12:41:52 -0700 [thread overview]
Message-ID: <20260701194153.401218-6-namhyung@kernel.org> (raw)
In-Reply-To: <20260701194153.401218-1-namhyung@kernel.org>
The first element of the kvm_usage string is allocated dynamically by
parse_options_subcommand() if it's NULL. Callers should free it after
use.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-kvm.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 20ea59e59a4b65ba..00baafb056032970 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -2135,6 +2135,7 @@ int cmd_kvm(int argc, const char **argv)
const char *const kvm_subcommands[] = { "top", "record", "report", "diff",
"buildid-list", "stat", NULL };
const char *kvm_usage[] = { NULL, NULL };
+ int ret;
exclude_GH_default = true;
perf_host = 0;
@@ -2152,18 +2153,18 @@ int cmd_kvm(int argc, const char **argv)
file_name = get_filename_for_perf_kvm();
if (strlen(argv[0]) > 2 && strstarts("record", argv[0]))
- return __cmd_record(file_name, argc, argv);
+ ret = __cmd_record(file_name, argc, argv);
else if (strlen(argv[0]) > 2 && strstarts("report", argv[0]))
- return __cmd_report(file_name, argc, argv);
+ ret = __cmd_report(file_name, argc, argv);
else if (strlen(argv[0]) > 2 && strstarts("diff", argv[0]))
- return cmd_diff(argc, argv);
+ ret = cmd_diff(argc, argv);
else if (!strcmp(argv[0], "top"))
- return __cmd_top(argc, argv);
+ ret = __cmd_top(argc, argv);
else if (strlen(argv[0]) > 2 && strstarts("buildid-list", argv[0]))
- return __cmd_buildid_list(file_name, argc, argv);
+ ret = __cmd_buildid_list(file_name, argc, argv);
#if defined(HAVE_LIBTRACEEVENT)
else if (strlen(argv[0]) > 2 && strstarts("stat", argv[0]))
- return kvm_cmd_stat(file_name, argc, argv);
+ ret = kvm_cmd_stat(file_name, argc, argv);
#endif
else
usage_with_options(kvm_usage, kvm_options);
@@ -2171,5 +2172,5 @@ int cmd_kvm(int argc, const char **argv)
/* free usage string allocated by parse_options_subcommand */
free((void *)kvm_usage[0]);
- return 0;
+ return ret;
}
--
2.55.0.rc0.799.gd6f94ed593-goog
next prev parent reply other threads:[~2026-07-01 19:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 19:41 [PATCH v3 0/6] perf kvm: A small update in the default arch event Namhyung Kim
2026-07-01 19:41 ` [PATCH v3 1/6] perf kvm: Factor out kvm_need_default_arch_event() Namhyung Kim
2026-07-01 19:59 ` sashiko-bot
2026-07-01 19:41 ` [PATCH v3 2/6] perf kvm: Check kvm_need_default_arch_event() early Namhyung Kim
2026-07-01 19:41 ` [PATCH v3 3/6] perf kvm: Kill STRDUP_FAIL_EXIT() Namhyung Kim
2026-07-01 19:41 ` [PATCH v3 4/6] perf kvm: Do not copy filename string Namhyung Kim
2026-07-01 19:41 ` Namhyung Kim [this message]
2026-07-01 19:41 ` [PATCH v3 6/6] perf test: Extend perf kvm tests to check default event Namhyung Kim
2026-07-01 20:11 ` sashiko-bot
2026-07-02 4:09 ` [PATCH v3 0/6] perf kvm: A small update in the default arch event Ian Rogers
2026-07-04 16:11 ` 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=20260701194153.401218-6-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.