qemuDomainRemoveDiskDevice would leak the disk to be removed if the VM
crashed since it was removed from the definition but not freed.
Broken in commit 105bcdde76b which moved the removal from the definition
earlier.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_hotplug.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 2ddcc19cc8..f1b18fcc7d 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3863,6 +3863,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
bool prUsed = false;
const char *authAlias = NULL;
const char *encAlias = NULL;
+ int ret = -1;
VIR_DEBUG("Removing disk %s from domain %p %s",
disk->info.alias, vm, vm->def->name);
@@ -3917,7 +3918,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
ignore_value(qemuMonitorDelObject(priv->mon, qemuDomainGetManagedPRAlias()));
if (qemuDomainObjExitMonitor(driver, vm) < 0)
- return -1;
+ goto cleanup;
virDomainAuditDisk(vm, disk->src, NULL, "detach", true);
@@ -3937,8 +3938,11 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
+ ret = 0;
+
+ cleanup:
virDomainDiskDefFree(disk);
- return 0;
+ return ret;
}
--
2.16.2