Fix leak in PCI hostdev hot-unplug

* src/qemu_driver.c: sync the hostdev hot-unplug code with the disk/net
  code.
This commit is contained in:
Mark McLoughlin 2009-09-17 15:32:45 +01:00
parent 8881ae1bf8
commit a70da51ff7

View File

@ -6206,14 +6206,20 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
pciFreeDevice(conn, pci); pciFreeDevice(conn, pci);
} }
if (i != --vm->def->nhostdevs) if (vm->def->nhostdevs > 1) {
memmove(&vm->def->hostdevs[i], memmove(vm->def->hostdevs + i,
&vm->def->hostdevs[i+1], vm->def->hostdevs + i + 1,
sizeof(*vm->def->hostdevs) * (vm->def->nhostdevs-i)); sizeof(*vm->def->hostdevs) *
(vm->def->nhostdevs - (i + 1)));
vm->def->nhostdevs--;
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs) < 0) { if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs) < 0) {
virReportOOMError(conn); /* ignore, harmless */
ret = -1;
} }
} else {
VIR_FREE(vm->def->hostdevs);
vm->def->nhostdevs = 0;
}
virDomainHostdevDefFree(detach);
return ret; return ret;
} }