From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 09/10] tests/qtest: Don't dup machine name in qtest_cb_for_every_machine callbacks
Date: Tue, 17 Mar 2026 15:23:19 -0300 [thread overview]
Message-ID: <20260317182320.31991-10-farosas@suse.de> (raw)
In-Reply-To: <20260317182320.31991-1-farosas@suse.de>
The qtest_get_machines function caches the list of machines in a
static variable. Dup'ing the machine->name string only serves to leak
that memory when a single test is executed.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Link: https://lore.kernel.org/qemu-devel/20260313182957.28432-2-farosas@suse.de
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
tests/qtest/cpu-plug-test.c | 11 +++++------
tests/qtest/qom-test.c | 3 +--
tests/qtest/test-hmp.c | 3 +--
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/tests/qtest/cpu-plug-test.c b/tests/qtest/cpu-plug-test.c
index 0aa4ccc5b6..e68f39cf56 100644
--- a/tests/qtest/cpu-plug-test.c
+++ b/tests/qtest/cpu-plug-test.c
@@ -14,7 +14,7 @@
#include "qobject/qlist.h"
struct PlugTestData {
- char *machine;
+ const char *machine;
const char *cpu_model;
char *device_model;
unsigned sockets;
@@ -73,7 +73,6 @@ static void test_data_free(gpointer data)
{
PlugTestData *pc = data;
- g_free(pc->machine);
g_free(pc->device_model);
g_free(pc);
}
@@ -87,7 +86,7 @@ static void add_pc_test_case(const char *mname)
return;
}
data = g_new(PlugTestData, 1);
- data->machine = g_strdup(mname);
+ data->machine = mname;
data->cpu_model = "Haswell"; /* 1.3+ theoretically */
data->device_model = g_strdup_printf("%s-%s-cpu", data->cpu_model,
qtest_get_arch());
@@ -114,7 +113,7 @@ static void add_pseries_test_case(const char *mname)
return;
}
data = g_new(PlugTestData, 1);
- data->machine = g_strdup(mname);
+ data->machine = mname;
data->cpu_model = "power8_v2.0";
data->device_model = g_strdup("power8_v2.0-spapr-cpu-core");
data->sockets = 2;
@@ -140,7 +139,7 @@ static void add_s390x_test_case(const char *mname)
}
data = g_new(PlugTestData, 1);
- data->machine = g_strdup(mname);
+ data->machine = mname;
data->cpu_model = "qemu";
data->device_model = g_strdup("qemu-s390x-cpu");
data->sockets = 1;
@@ -162,7 +161,7 @@ static void add_loongarch_test_case(const char *mname)
PlugTestData *data;
data = g_new(PlugTestData, 1);
- data->machine = g_strdup(mname);
+ data->machine = mname;
data->cpu_model = "la464";
data->device_model = g_strdup("la464-loongarch-cpu");
data->sockets = 1;
diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c
index 2da9918e16..6421f2d9d9 100644
--- a/tests/qtest/qom-test.c
+++ b/tests/qtest/qom-test.c
@@ -216,7 +216,6 @@ static void test_machine(gconstpointer data)
test_list_get_value(qts);
qtest_quit(qts);
- g_free((void *)machine);
}
static void add_machine_test_case(const char *mname)
@@ -224,7 +223,7 @@ static void add_machine_test_case(const char *mname)
char *path;
path = g_strdup_printf("qom/%s", mname);
- qtest_add_data_func(path, g_strdup(mname), test_machine);
+ qtest_add_data_func(path, mname, test_machine);
g_free(path);
}
diff --git a/tests/qtest/test-hmp.c b/tests/qtest/test-hmp.c
index 1b2e07522f..60f742e83f 100644
--- a/tests/qtest/test-hmp.c
+++ b/tests/qtest/test-hmp.c
@@ -135,7 +135,6 @@ static void test_machine(gconstpointer data)
qtest_quit(qts);
g_free(args);
- g_free((void *)data);
}
static void add_machine_test_case(const char *mname)
@@ -143,7 +142,7 @@ static void add_machine_test_case(const char *mname)
char *path;
path = g_strdup_printf("hmp/%s", mname);
- qtest_add_data_func(path, g_strdup(mname), test_machine);
+ qtest_add_data_func(path, mname, test_machine);
g_free(path);
}
--
2.51.0
next prev parent reply other threads:[~2026-03-17 18:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 18:23 [PULL 00/10] Migration/Qtest patches for 2026-03-17 Fabiano Rosas
2026-03-17 18:23 ` [PULL 01/10] tests/qtest/migration: Fix leak of migration tests data Fabiano Rosas
2026-03-17 18:23 ` [PULL 02/10] io: Fix TLS bye task leak Fabiano Rosas
2026-03-18 20:36 ` Michael Tokarev
2026-03-19 8:57 ` Daniel P. Berrangé
2026-03-17 18:23 ` [PULL 03/10] tests/qtest/migration: Fix leak in CPR exec test Fabiano Rosas
2026-03-17 18:23 ` [PULL 04/10] migration/multifd: Fix leaks of TLS error objects Fabiano Rosas
2026-03-17 18:23 ` [PULL 05/10] tests/qtest/migration: Force exit-on-error=false Fabiano Rosas
2026-03-26 9:02 ` Thomas Huth
2026-03-26 13:28 ` Fabiano Rosas
2026-03-17 18:23 ` [PULL 06/10] migration: assert that the same migration handler is not being added twice Fabiano Rosas
2026-03-17 18:23 ` [PULL 07/10] migration/options: Fix leaks in StrOrNull qdev accessors Fabiano Rosas
2026-03-17 18:23 ` [PULL 08/10] migration: fix implicit integer division in migration_update_counters Fabiano Rosas
2026-03-17 18:23 ` Fabiano Rosas [this message]
2026-03-17 18:23 ` [PULL 10/10] tests/qtest/test-hmp: Free machine options Fabiano Rosas
2026-03-18 13:26 ` [PULL 00/10] Migration/Qtest patches for 2026-03-17 Peter Maydell
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=20260317182320.31991-10-farosas@suse.de \
--to=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.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