diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index fe176f35e4194752c7f02573f17ed132985a2b2e..9c63d0aebd5c159a9c70d4cf340fd7516dbfeebc 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -240,11 +240,6 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs) virObjectUnref(pcidevs); return NULL; } - if (virPCIDeviceListAdd(pcidevs, pci) < 0) { - virPCIDeviceFree(pci); - virObjectUnref(pcidevs); - return NULL; - } virPCIDeviceSetManaged(pci, hostdev->managed); @@ -254,6 +249,12 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs) virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); else virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM); + + if (virPCIDeviceListAdd(pcidevs, pci) < 0) { + virPCIDeviceFree(pci); + virObjectUnref(pcidevs); + return NULL; + } } return pcidevs;