]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
hostdev: Fix index error in loop after remove an element
authorHuanle Han <hanxueluo@gmail.com>
Thu, 26 Mar 2015 14:23:46 +0000 (22:23 +0800)
committerMartin Kletzander <mkletzan@redhat.com>
Thu, 2 Apr 2015 14:05:32 +0000 (16:05 +0200)
'virPCIDeviceList' is actually an array. Removing one element makes the
rest of the element move.

Use while loop, increase index only when not virPCIDeviceListDel(pcidevs, dev)

Signed-off-by: Huanle Han <hanxueluo@gmail.com>
src/util/virhostdev.c

index 23365a3129ef1d3bd16e2e3ee602db68d4f8ba86..83f567d307a4f06503eaf61240f11f86bace095f 100644 (file)
@@ -785,7 +785,8 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr,
      * them and reset all the devices before re-attach.
      * Attach mac and port profile parameters to devices
      */
-    for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+    i = 0;
+    while (i < virPCIDeviceListCount(pcidevs)) {
         virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
         virPCIDevicePtr activeDev = NULL;
 
@@ -806,6 +807,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr,
         }
 
         virPCIDeviceListDel(hostdev_mgr->activePCIHostdevs, dev);
+        i++;
     }
 
     /* At this point, any device that had been used by the guest is in