From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4DtI-0002W4-Ul for qemu-devel@nongnu.org; Wed, 02 Dec 2015 15:20:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a4DtF-0003Vv-OX for qemu-devel@nongnu.org; Wed, 02 Dec 2015 15:20:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41721) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4DtF-0003Ve-HG for qemu-devel@nongnu.org; Wed, 02 Dec 2015 15:20:37 -0500 From: Markus Armbruster Date: Wed, 2 Dec 2015 21:20:34 +0100 Message-Id: <1449087634-30846-3-git-send-email-armbru@redhat.com> In-Reply-To: <1449087634-30846-1-git-send-email-armbru@redhat.com> References: <1449087634-30846-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-2.5 2/2] qom-test: fix qmp() leaks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, afaerber@suse.de, peter.maydell@linaro.org 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 Message-Id: <1448551895-871-1-git-send-email-marcandre.lureau@redhat.com> [Straightforwardly rebased onto the previous patch] Signed-off-by: Markus Armbruster --- tests/qom-test.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/qom-test.c b/tests/qom-test.c index fde04e7..3e5e873 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,14 +76,16 @@ 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) @@ -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((void *)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.4.3