[libvirt] [PATCH 05/10] qemu: hotplug: Don't leak 'disk' if VM crashes during unplug finishing

Peter Krempa posted 10 patches 7 years, 6 months ago
[libvirt] [PATCH 05/10] qemu: hotplug: Don't leak 'disk' if VM crashes during unplug finishing
Posted by Peter Krempa 7 years, 6 months ago
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@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 05/10] qemu: hotplug: Don't leak 'disk' if VM crashes during unplug finishing
Posted by Ján Tomko 7 years, 6 months ago
On Tue, Jul 17, 2018 at 02:14:25PM +0200, Peter Krempa wrote:
>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@redhat.com>
>---
> src/qemu/qemu_hotplug.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list