Received: from eggs.gnu.org ([2001:4830:134:3::10]:45203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPBCr-0005wZ-Ai for qemu-devel@nongnu.org; Fri, 29 Jan 2016 10:43:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPBCq-0000Sy-GU for qemu-devel@nongnu.org; Fri, 29 Jan 2016 10:43:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPBCq-0000Sr-93 for qemu-devel@nongnu.org; Fri, 29 Jan 2016 10:43:28 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id BE2715BA02 for ; Fri, 29 Jan 2016 15:43:27 +0000 (UTC) From: Markus Armbruster References: <1450697444-30119-1-git-send-email-marcandre.lureau@redhat.com> <1450697444-30119-5-git-send-email-marcandre.lureau@redhat.com> Date: Fri, 29 Jan 2016 16:43:24 +0100 In-Reply-To: <1450697444-30119-5-git-send-email-marcandre.lureau@redhat.com> (marcandre lureau's message of "Mon, 21 Dec 2015 12:30:40 +0100") Message-ID: <87egd075nn.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 4/8] libqos: remove some 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 > > qpci_device_find() returns allocated data, don't leak it. > > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > tests/libqos/pci.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c > index 4e630c2..80b1a21 100644 > --- a/tests/libqos/pci.c > +++ b/tests/libqos/pci.c > @@ -34,11 +34,13 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id,= int device_id, for (slot =3D 0; slot < 32; slot++) { int fn; for (fn =3D 0; fn < 8; fn++) { QPCIDevice *dev; dev =3D qpci_device_find(bus, QPCI_DEVFN(slot, fn)); if (!dev) { continue; } >=20=20 > if (vendor_id !=3D -1 && > qpci_config_readw(dev, PCI_VENDOR_ID) !=3D vendor_id) { > + g_free(dev); > continue; > } >=20=20 > if (device_id !=3D -1 && > qpci_config_readw(dev, PCI_DEVICE_ID) !=3D device_id) { > + g_free(dev); > continue; > } func(dev, QPCI_DEVFN(slot, fn), data); } } } The existing users pass a func that saves dev, and free the saved dev later. Works as long as we call func() at most once. If multiple devices match, all but the last one are leaked. Can this happen?