[PATCH 3/3] qemu: Fix memory leak fix memory leak in the condition of attaching cdrom

Jiacheng Jiang jiangjiacheng at huawei.com
Fri Sep 9 06:10:13 UTC 2022


From: jiangjiacheng <jiangjiacheng at huawei.com>

The qemuDomainAttachDeviceLive interface is invoked for attaching cdrom in
the same way as common disks. The difference is that attach cdrom only update
the src of the original device while common disk will add new disk to vm's
device list. Therefore, the dev->data.disk should be freed to avoid memory leak
when attach cdrom as well as floppy.

Signed-off-by: jiangjiacheng <jiangjiacheng at huawei.com>
---
 src/qemu/qemu_driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c43bc4070e..64b1ca3f39 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6882,6 +6882,9 @@ qemuDomainAttachDeviceLive(virDomainObj *vm,
         ret = qemuDomainAttachDeviceDiskLive(driver, vm, dev);
         if (!ret) {
             alias = dev->data.disk->info.alias;
+            if ((virDomainDiskDevice)dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
+                (virDomainDiskDevice)dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+                virDomainDiskDefFree(dev->data.disk);
             dev->data.disk = NULL;
         }
         break;
-- 
2.33.0



More information about the libvir-list mailing list