]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix a crash when restarting libvirtd.
authorChris Lalancette <clalance@redhat.com>
Mon, 25 Jan 2010 16:13:41 +0000 (11:13 -0500)
committerChris Lalancette <clalance@redhat.com>
Mon, 25 Jan 2010 21:25:47 +0000 (16:25 -0500)
If you shutdown libvirtd while a domain with PCI
devices is running, then try to restart libvirtd,
libvirtd will crash.

This happens because qemuUpdateActivePciHostdevs() is calling
pciDeviceListSteal() with a dev of 0x0 (NULL), and then trying
to dereference it.  This patch fixes it up so that
qemuUpdateActivePciHostdevs() steals the devices after first
Get()'ting them, avoiding the crash.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
src/qemu/qemu_driver.c

index 16e9b565b5a8223658cba598de5ce8f606175fd2..adf962a842a92e13b27c56259597336717b1d149 100644 (file)
@@ -2147,6 +2147,7 @@ qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
                             virDomainDefPtr def)
 {
     pciDeviceList *pcidevs;
+    int i;
     int ret = -1;
 
     if (!def->nhostdevs)
@@ -2155,8 +2156,9 @@ qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
     if (!(pcidevs = qemuGetPciHostDeviceList(NULL, def)))
         return -1;
 
-    while (pciDeviceListCount(pcidevs) > 0) {
-        pciDevice *dev = pciDeviceListSteal(NULL, pcidevs, 0);
+    for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
+        pciDevice *dev = pciDeviceListGet(pcidevs, i);
+        pciDeviceListSteal(NULL, pcidevs, dev);
         if (pciDeviceListAdd(NULL,
                              driver->activePciHostdevs,
                              dev) < 0) {