From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1yWZ-0002DW-3H for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:31:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1yWV-00041R-Nw for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:31:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50135) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1yWV-00041M-Ib for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:31:51 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 4301C68E35 for ; Thu, 26 Nov 2015 15:31:51 +0000 (UTC) From: marcandre.lureau@redhat.com Date: Thu, 26 Nov 2015 16:31:35 +0100 Message-Id: <1448551895-871-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] qom-test: fix qmp() leaks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com From: Marc-Andr=C3=A9 Lureau Before this patch ASAN reported: SUMMARY: AddressSanitizer: 677165875 byte(s) leaked in 1272437 allocation= (s) After this patch: SUMMARY: AddressSanitizer: 465 byte(s) leaked in 32 allocation(s) Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/qom-test.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/qom-test.c b/tests/qom-test.c index fde04e7..8a08fd7 100644 --- a/tests/qom-test.c +++ b/tests/qom-test.c @@ -47,7 +47,7 @@ static bool is_blacklisted(const char *arch, const char= *mach) static void test_properties(const char *path, bool recurse) { char *child_path; - QDict *response, *tuple; + QDict *response, *tuple, *tmp; QList *list; QListEntry *entry; =20 @@ -57,6 +57,7 @@ static void test_properties(const char *path, bool recu= rse) g_assert(response); =20 if (!recurse) { + QDECREF(response); return; } =20 @@ -75,19 +76,21 @@ static void test_properties(const char *path, bool re= curse) } else { const char *prop =3D qdict_get_str(tuple, "name"); g_test_message("Testing property %s.%s", path, prop); - response =3D qmp("{ 'execute': 'qom-get'," - " 'arguments': { 'path': %s," - " 'property': %s } }", - path, prop); + tmp =3D qmp("{ 'execute': 'qom-get'," + " 'arguments': { 'path': %s," + " 'property': %s } }", + path, prop); /* qom-get may fail but should not, e.g., segfault. */ - g_assert(response); + g_assert(tmp); + QDECREF(tmp); } } + QDECREF(response); } =20 -static void test_machine(gconstpointer data) +static void test_machine(gpointer data) { - const char *machine =3D data; + char *machine =3D data; char *args; QDict *response; =20 @@ -98,9 +101,11 @@ static void test_machine(gconstpointer data) =20 response =3D qmp("{ 'execute': 'quit' }"); g_assert(qdict_haskey(response, "return")); + QDECREF(response); =20 qtest_end(); g_free(args); + g_free(machine); } =20 static void add_machine_test_cases(void) @@ -129,10 +134,12 @@ static void add_machine_test_cases(void) mname =3D qstring_get_str(qstr); if (!is_blacklisted(arch, mname)) { path =3D g_strdup_printf("qom/%s", mname); - qtest_add_data_func(path, mname, test_machine); + qtest_add_data_func(path, g_strdup(mname), test_machine); } } + qtest_end(); + QDECREF(response); } =20 int main(int argc, char **argv) --=20 2.5.0