[libvirt] [PATCH 2/2] Fix leak in PCI hostdev hot-unplug

Daniel P. Berrange berrange at redhat.com
Mon Sep 21 11:40:39 UTC 2009


On Thu, Sep 17, 2009 at 04:03:00PM +0100, Mark McLoughlin wrote:
> * src/qemu_driver.c: sync the hostdev hot-unplug code with the disk/net
>   code.
> ---
>  src/qemu_driver.c |   20 +++++++++++++-------
>  1 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/src/qemu_driver.c b/src/qemu_driver.c
> index de31581..2ddcdc0 100644
> --- a/src/qemu_driver.c
> +++ b/src/qemu_driver.c
> @@ -6206,14 +6206,20 @@ static int
> qemudDomainDetachHostPciDevice(virConnectPtr conn,
>          pciFreeDevice(conn, pci);
>      }
>  
> -    if (i != --vm->def->nhostdevs)
> -        memmove(&vm->def->hostdevs[i],
> -                &vm->def->hostdevs[i+1],
> -                sizeof(*vm->def->hostdevs) * (vm->def->nhostdevs-i));
> -    if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs) < 0) {
> -        virReportOOMError(conn);
> -        ret = -1;
> +    if (vm->def->nhostdevs > 1) {
> +        memmove(vm->def->hostdevs + i,
> +                vm->def->hostdevs + i + 1,
> +                sizeof(*vm->def->hostdevs) *
> +                (vm->def->nhostdevs - (i + 1)));
> +        vm->def->nhostdevs--;
> +        if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs) < 0) {
> +            /* ignore, harmless */
> +        }
> +    } else {
> +        VIR_FREE(vm->def->hostdevs);
> +        vm->def->nhostdevs = 0;
>      }
> +    virDomainHostdevDefFree(detach);
>  
>      return ret;
>  }
> -- 

ACK


Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list