marcandre.lur...@redhat.com writes: > From: Marc-André Lureau <marcandre.lur...@redhat.com> > > qpci_device_find() returns allocated data, don't leak it. > > Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> > --- > 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 = 0; slot < 32; slot++) { int fn;
for (fn = 0; fn < 8; fn++) { QPCIDevice *dev; dev = qpci_device_find(bus, QPCI_DEVFN(slot, fn)); if (!dev) { continue; } > > if (vendor_id != -1 && > qpci_config_readw(dev, PCI_VENDOR_ID) != vendor_id) { > + g_free(dev); > continue; > } > > if (device_id != -1 && > qpci_config_readw(dev, PCI_DEVICE_ID) != 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?