]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix leak in PCI hostdev hot-unplug
authorMark McLoughlin <markmc@redhat.com>
Thu, 17 Sep 2009 14:32:45 +0000 (15:32 +0100)
committerMark McLoughlin <markmc@redhat.com>
Mon, 21 Sep 2009 11:45:34 +0000 (12:45 +0100)
* src/qemu_driver.c: sync the hostdev hot-unplug code with the disk/net
  code.

src/qemu_driver.c

index de31581322172f07025d7ee9fe743d6b80f5e54c..2ddcdc0f6e4d6af910d5618d9e851c82aee0842e 100644 (file)
@@ -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;
 }