From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyJKi-0003zl-Fg for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:33:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyJKh-0002lg-Gu for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:33:20 -0400 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:32904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyJKh-0002lS-54 for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:33:19 -0400 Received: by mail-lf0-x244.google.com with SMTP id r36so3405446lfi.0 for ; Wed, 12 Apr 2017 07:33:19 -0700 (PDT) MIME-Version: 1.0 References: <20170410142112.11550-1-marcandre.lureau@redhat.com> <8737ddna9i.fsf@dusky.pond.sub.org> In-Reply-To: <8737ddna9i.fsf@dusky.pond.sub.org> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Wed, 12 Apr 2017 14:33:07 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] test-keyval: fix leaks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org Hi On Wed, Apr 12, 2017 at 3:19 PM Markus Armbruster wrote= : > Marc-Andr=C3=A9 Lureau writes: > > > Signed-off-by: Marc-Andr=C3=A9 Lureau > > --- > > tests/test-keyval.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/tests/test-keyval.c b/tests/test-keyval.c > > index ba19560a22..141ee5d0c4 100644 > > --- a/tests/test-keyval.c > > +++ b/tests/test-keyval.c > > @@ -628,6 +628,7 @@ static void test_keyval_visit_alternate(void) > > visit_type_AltNumStr(v, "a", &ans, &error_abort); > > g_assert_cmpint(ans->type, =3D=3D, QTYPE_QSTRING); > > g_assert_cmpstr(ans->u.s, =3D=3D, "1"); > > + qapi_free_AltNumStr(ans); > > visit_type_AltNumInt(v, "a", &ani, &err); > > error_free_or_abort(&err); > > visit_end_struct(v, NULL); > > @@ -649,11 +650,14 @@ static void test_keyval_visit_any(void) > > visit_type_any(v, "a", &any, &error_abort); > > @any becomes a strong reference (qobject_input_type_any() increments the > reference count). > > > qlist =3D qobject_to_qlist(any); > > Reference count unchanged. > > > g_assert(qlist); > > + qobject_decref(any); > > Uh, this is unnecessarily dirty: you relinquish the reference before > you're actually done with it. Works only because there's *another* > reference hiding within @v. Let's move this ... > > > qstr =3D qobject_to_qstring(qlist_pop(qlist)); > > g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "null"); > > + QDECREF(qstr); > > qstr =3D qobject_to_qstring(qlist_pop(qlist)); > > g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "1"); > > g_assert(qlist_empty(qlist)); > > + QDECREF(qstr); > > ... here. Okay to do that on commit? > sure, makes sense > > visit_check_struct(v, &error_abort); > > visit_end_struct(v, NULL); > > visit_free(v); > > With the reference counting cleaned up: > Reviewed-by: Markus Armbruster > > thanks --=20 Marc-Andr=C3=A9 Lureau