Received: from eggs.gnu.org ([2001:4830:134:3::10]:36141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4CUK-0000LJ-Vy for qemu-devel@nongnu.org; Wed, 02 Dec 2015 13:50:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a4CUH-0008Rh-Pm for qemu-devel@nongnu.org; Wed, 02 Dec 2015 13:50:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40502) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4CUH-0008RW-IJ for qemu-devel@nongnu.org; Wed, 02 Dec 2015 13:50:45 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 2B2472C9DA9 for ; Wed, 2 Dec 2015 18:50:45 +0000 (UTC) From: Markus Armbruster References: <1448551895-871-1-git-send-email-marcandre.lureau@redhat.com> Date: Wed, 02 Dec 2015 19:50:42 +0100 In-Reply-To: <1448551895-871-1-git-send-email-marcandre.lureau@redhat.com> (marcandre lureau's message of "Thu, 26 Nov 2015 16:31:35 +0100") Message-ID: <87lh9celbx.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] qom-test: fix qmp() leaks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com Cc: qemu-devel@nongnu.org marcandre.lureau@redhat.com writes: > 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=20 > @@ -57,6 +57,7 @@ static void test_properties(const char *path, bool recu= rse) > g_assert(response); >=20=20 > if (!recurse) { > + QDECREF(response); > return; > } >=20=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=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=20 Why drop const? > @@ -98,9 +101,11 @@ static void test_machine(gconstpointer data) >=20=20 > response =3D qmp("{ 'execute': 'quit' }"); > g_assert(qdict_haskey(response, "return")); > + QDECREF(response); >=20=20 > qtest_end(); > g_free(args); > + g_free(machine); Hmm, I guess so you can g_free() without a cast. > } >=20=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); I wonder why changing test_machine()'s type doesn't make the compiler gripe here... argh! void qtest_add_data_func(const char *str, const void *data, void (*fn)); void (*fn) is just a stupid way to write void *fn. Bye-bye type-checking. I'll post a patch fixing this. > } > } > + > qtest_end(); > + QDECREF(response); > } >=20=20 > int main(int argc, char **argv) Reviewed-by: Markus Armbruster I intend to rebase this patch onto mine. Changes should be trivial, though.