Skip to content

Commit f0d7477

Browse files
pm215Fabiano Rosas
authored andcommitted
tests/qtest/migration-test: Fix leaks in calc_dirtyrate_ready()
In calc_dirtyrate_ready() we g_strdup() a string but then never free it: Direct leak of 19 byte(s) in 2 object(s) allocated from: #0 0x55ead613413e in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/asan/tests/qtest/migration-test+0x22f13e) (BuildId: e7cd5c37b2987a1af682b43ee5240b98bb316737) #1 0x7f7a13d39738 in g_malloc debian/build/deb/../../../glib/gmem.c:128:13 #2 0x7f7a13d4e583 in g_strdup debian/build/deb/../../../glib/gstrfuncs.c:361:17 #3 0x55ead6266f48 in calc_dirtyrate_ready tests/qtest/migration-test.c:3409:14 #4 0x55ead62669fe in wait_for_calc_dirtyrate_complete tests/qtest/migration-test.c:3422:13 qemu#5 0x55ead6253df7 in test_vcpu_dirty_limit tests/qtest/migration-test.c:3562:9 qemu#6 0x55ead626a407 in migration_test_wrapper tests/qtest/migration-helpers.c:456:5 We also fail to unref the QMP rsp_return, so we leak that also. Rather than duplicating the string, use the in-place value from the qdict, and then unref the qdict. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Fabiano Rosas <farosas@suse.de>
1 parent 0fa2cf8 commit f0d7477

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/qtest/migration-test.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,15 +3318,18 @@ static QDict *query_vcpu_dirty_limit(QTestState *who)
33183318
static bool calc_dirtyrate_ready(QTestState *who)
33193319
{
33203320
QDict *rsp_return;
3321-
gchar *status;
3321+
const char *status;
3322+
bool ready;
33223323

33233324
rsp_return = query_dirty_rate(who);
33243325
g_assert(rsp_return);
33253326

3326-
status = g_strdup(qdict_get_str(rsp_return, "status"));
3327+
status = qdict_get_str(rsp_return, "status");
33273328
g_assert(status);
3329+
ready = g_strcmp0(status, "measuring");
3330+
qobject_unref(rsp_return);
33283331

3329-
return g_strcmp0(status, "measuring");
3332+
return ready;
33303333
}
33313334

33323335
static void wait_for_calc_dirtyrate_complete(QTestState *who,

0 commit comments

Comments
 (0)