[PATCH v3 4/6] perf kvm: Do not copy filename string

From: Namhyung Kim

Date: Wed Jul 01 2026 - 16:09:18 EST


As it removed STRDUP_FAIL_EXIT(), it no longer calls free() for elements
in the copied argv. Thus, the filename should not be allocated as well.
In fact, it's a pointer to string literals and should be fine to pass
the pointer.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-kvm.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index eaf9297cc34d32c1..20ea59e59a4b65ba 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -607,11 +607,11 @@ static const char *get_filename_for_perf_kvm(void)
const char *filename;

if (perf_host && !perf_guest)
- filename = strdup("perf.data.host");
+ filename = "perf.data.host";
else if (!perf_host && perf_guest)
- filename = strdup("perf.data.guest");
+ filename = "perf.data.guest";
else
- filename = strdup("perf.data.kvm");
+ filename = "perf.data.kvm";

return filename;
}
@@ -2148,15 +2148,9 @@ int cmd_kvm(int argc, const char **argv)
if (!perf_host)
perf_guest = 1;

- if (!file_name) {
+ if (!file_name)
file_name = get_filename_for_perf_kvm();

- if (!file_name) {
- pr_err("Failed to allocate memory for filename\n");
- return -ENOMEM;
- }
- }
-
if (strlen(argv[0]) > 2 && strstarts("record", argv[0]))
return __cmd_record(file_name, argc, argv);
else if (strlen(argv[0]) > 2 && strstarts("report", argv[0]))
--
2.55.0.rc0.799.gd6f94ed593-goog