Skip to content

Commit 9ab4fb2

Browse files
Kuhn-Chenhuth
authored andcommitted
tests/migration: fix memleak in wait_command/wait_command_fd
Properly free each command resp to avoid memory leak. ASAN shows memory leak stack: Indirect leak of 2352520 byte(s) in 571 object(s) allocated from: #0 0x7f6ca3308d4e in __interceptor_calloc (/lib64/libasan.so.5+0x112d4e) #1 0x7f6ca3127a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50) #2 0x557bf3c71d2b in qdict_new ../qobject/qdict.c:29 #3 0x557bf3c9caba in parse_object ../qobject/json-parser.c:318 #4 0x557bf3c9ce75 in json_parser_parse ../qobject/json-parser.c:580 #5 0x557bf3c8c8cf in json_message_process_token ../qobject/json-streamer.c:92 #6 0x557bf3c9ea59 in json_lexer_feed_char ../qobject/json-lexer.c:313 #7 0x557bf3c9eeb5 in json_lexer_feed ../qobject/json-lexer.c:350 #8 0x557bf3c4793a in qmp_fd_receive ../tests/qtest/libqtest.c:608 #9 0x557bf3c47b58 in qtest_qmp_receive ../tests/qtest/libqtest.c:618 #10 0x557bf3c44245 in wait_command ../tests/qtest/migration-helpers.c:59 #11 0x557bf3c445cb in migrate_query_status ../tests/qtest/migration-helpers.c:108 #12 0x557bf3c44642 in check_migration_status ../tests/qtest/migration-helpers.c:124 #13 0x557bf3c447e7 in wait_for_migration_status ../tests/qtest/migration-helpers.c:148 #14 0x557bf3c43b8f in test_migrate_auto_converge ../tests/qtest/migration-test.c:1243 ...... Fix: 5e34005 Reported-by: Euler Robot <[email protected]> Signed-off-by: Chen Qun <[email protected]> Message-Id: <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent 4c5b97b commit 9ab4fb2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/qtest/migration-helpers.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void check_stop_event(QTestState *who)
3232
QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
3333
{
3434
va_list ap;
35-
QDict *resp;
35+
QDict *resp, *ret;
3636

3737
va_start(ap, command);
3838
qtest_qmp_vsend_fds(who, &fd, 1, command, ap);
@@ -44,7 +44,11 @@ QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
4444
g_assert(!qdict_haskey(resp, "error"));
4545
g_assert(qdict_haskey(resp, "return"));
4646

47-
return qdict_get_qdict(resp, "return");
47+
ret = qdict_get_qdict(resp, "return");
48+
qobject_ref(ret);
49+
qobject_unref(resp);
50+
51+
return ret;
4852
}
4953

5054
/*
@@ -53,7 +57,7 @@ QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
5357
QDict *wait_command(QTestState *who, const char *command, ...)
5458
{
5559
va_list ap;
56-
QDict *resp;
60+
QDict *resp, *ret;
5761

5862
va_start(ap, command);
5963
resp = qtest_vqmp(who, command, ap);
@@ -64,7 +68,11 @@ QDict *wait_command(QTestState *who, const char *command, ...)
6468
g_assert(!qdict_haskey(resp, "error"));
6569
g_assert(qdict_haskey(resp, "return"));
6670

67-
return qdict_get_qdict(resp, "return");
71+
ret = qdict_get_qdict(resp, "return");
72+
qobject_ref(ret);
73+
qobject_unref(resp);
74+
75+
return ret;
6876
}
6977

7078
/*

0 commit comments

Comments
 (0)