aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2020-01-16 15:07:36 +0100
committerThomas Huth <thuth@redhat.com>2020-01-16 17:01:25 +0100
commit99fd3178a0d6f8edbf22b5e82b3e5134f93c4084 (patch)
treef8546f0f6f28d662b217b505166f3cd8c441a997 /tests
parent16c5c6928ff53bd95e6504301ef6c285501531e7 (diff)
tests/qtest/vhost-user-test: Fix memory leaks
Do not allocate resources in case we return early, and make sure to free dest_cmdline at the end. Reported-by: Euler Robot <euler.robot@huawei.com> Reported-by: Pan Nengyuan <pannengyuan@huawei.com> Message-Id: <20200116140736.9498-1-thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qtest/vhost-user-test.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index 2324b964ad..9ee0f1e4fd 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -707,9 +707,9 @@ static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *alloc)
static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc)
{
TestServer *s = arg;
- TestServer *dest = test_server_new("dest");
- GString *dest_cmdline = g_string_new(qos_get_current_command_line());
- char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path);
+ TestServer *dest;
+ GString *dest_cmdline;
+ char *uri;
QTestState *to;
GSource *source;
QDict *rsp;
@@ -720,6 +720,10 @@ static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc)
return;
}
+ dest = test_server_new("dest");
+ dest_cmdline = g_string_new(qos_get_current_command_line());
+ uri = g_strdup_printf("%s%s", "unix:", dest->mig_path);
+
size = get_log_size(s);
g_assert_cmpint(size, ==, (256 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));
@@ -778,6 +782,7 @@ static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc)
qtest_quit(to);
test_server_free(dest);
g_free(uri);
+ g_string_free(dest_cmdline, true);
}
static void wait_for_rings_started(TestServer *s, size_t count)