Received: from eggs.gnu.org ([2001:4830:134:3::10]:53329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxbvI-0001pD-Eh for qemu-devel@nongnu.org; Fri, 21 Oct 2016 11:39:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxbvH-0007Cc-8P for qemu-devel@nongnu.org; Fri, 21 Oct 2016 11:39:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44412) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxbvH-0007Bz-0V for qemu-devel@nongnu.org; Fri, 21 Oct 2016 11:39:55 -0400 References: <1476787052-27333-1-git-send-email-ptoscano@redhat.com> <877f91ztpr.fsf@dusky.pond.sub.org> From: Eric Blake Message-ID: Date: Fri, 21 Oct 2016 10:39:53 -0500 MIME-Version: 1.0 In-Reply-To: <877f91ztpr.fsf@dusky.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PvVjN9fQR6L0AeEkSHcGGJC58Xp2Q0lQ1" Subject: Re: [Qemu-devel] [PATCH v2] qapi: fix memory leak in QmpOutputVisitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , Pino Toscano Cc: qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --PvVjN9fQR6L0AeEkSHcGGJC58Xp2Q0lQ1 From: Eric Blake To: Markus Armbruster , Pino Toscano Cc: qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com Message-ID: Subject: Re: [Qemu-devel] [PATCH v2] qapi: fix memory leak in QmpOutputVisitor References: <1476787052-27333-1-git-send-email-ptoscano@redhat.com> <877f91ztpr.fsf@dusky.pond.sub.org> In-Reply-To: <877f91ztpr.fsf@dusky.pond.sub.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/21/2016 09:01 AM, Markus Armbruster wrote: > Pino Toscano writes: >=20 >> qmp_output_start_struct() and qmp_output_start_list() create a new >> QObject (QDict, QList) and push it to the stack of the QmpOutputVisito= r, >> where it is saved as 'value'. When freeing the iterator in >> qmp_output_free(), these values are never freed properly. >> >> The simple solution is to qobject_decref() them. >> >> Signed-off-by: Pino Toscano >> --- >> >> Changes in v2: >> - added Signed-off-by >> >> qapi/qmp-output-visitor.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c >> index 9e3b67c..eedf256 100644 >> --- a/qapi/qmp-output-visitor.c >> +++ b/qapi/qmp-output-visitor.c >> @@ -220,6 +220,7 @@ static void qmp_output_free(Visitor *v) >> while (!QSLIST_EMPTY(&qov->stack)) { >> e =3D QSLIST_FIRST(&qov->stack); >> QSLIST_REMOVE_HEAD(&qov->stack, node); >> + qobject_decref(e->value); >> g_free(e); >> } >=20 > Hmm. The patch looks correct, even though it adds a decref very simila= r > to the one deleted by commit f24582d "qapi: fix double free in > qmp_output_visitor_cleanup()". As of that commit, we indeed had a QObject being added to both the stack (qmp_output_push) and to the parent container (qmp_output_add) at the same time, where freeing the parent container is recursive (decref on the root), and therefore we don't have to worry about the stack. > I suspect the bug you fix was introduced > by commit 455ba08 "qmp: Don't abuse stack to track qmp-output root". > Eric? No, I don't see how that changed anything. It moved where the root object was stored, but we still have the scenario where each newly-created QObject is being stored in two places (the stack, and the parent container), and where recursively freeing the parent container should be good enough. >=20 > Should this go into -stable? I'm still not convinced this patch makes sense. I'm now trying to reproduce the problem under valgrind, to see if this is an actual bug here, or if it is a bug in some other part of the code that is not properly cleaning up after a visit. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --PvVjN9fQR6L0AeEkSHcGGJC58Xp2Q0lQ1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYCjbJAAoJEKeha0olJ0NqEnkH/29Y0ALLghskz7WQ8/1v508L nBuLfhXIHjRj6ej10Y/w4hFSYJeKxn3GqsOUy0A6d/KDUUBErnr1ZE5+H+tZqrGW VAIBS/cEW3CMnpNL8l0ncgqS2J+gHzcNVcEUbkpW1hFu45Nu2bjrf7nBSRFmpS5Q PE2R67Uz5swERb2HX4Kfr4bN5FtnqBum2fVaZl7yLPVRDua1L42ObMpGeL9gsFZO 8nzfVUFXj8r45flUjuLP8G/DNJPRbmuvfF84ImYSJhUtzfEBx7uRR+AcXnemlUSJ 0AdVrF0cmQdilHsj7tiXRmlpDSl3KrrRxhh6gijzkFHiaqfpfb3VXqKIf63xFi8= =rqj/ -----END PGP SIGNATURE----- --PvVjN9fQR6L0AeEkSHcGGJC58Xp2Q0lQ1--