qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 4/8] libqos: remove some leaks


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH 4/8] libqos: remove some leaks
Date: Fri, 29 Jan 2016 16:43:24 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

address@hidden writes:

> From: Marc-André Lureau <address@hidden>
>
> qpci_device_find() returns allocated data, don't leak it.
>
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
>  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?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]