[PATCH] qemu: fix memleaks in qemuDomainAttachDeviceLive()

Jin Yan posted 1 patch 3 years, 9 months ago
Failed in applying to current master (apply log)
src/qemu/qemu_hotplug.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] qemu: fix memleaks in qemuDomainAttachDeviceLive()
Posted by Jin Yan 3 years, 9 months ago
 From e46e168f9767b8b291f23217fc7a62163c82eaf8 Mon Sep 17 00:00:00 2001
From: Jin Yan <jinyan12@huawei.com>
Date: Tue, 7 Jul 2020 21:58:52 +0800
Subject: [PATCH] qemu: fix memleaks in qemuDomainAttachDeviceLive()

During disk hotplugging, qemuDomainAttachDeviceLive() add the new
disk to the device list of the VM object. However, hotplugging
cdroms and floppies only updates the src variable of the original
disk device, so the newly generated disk object needs to be released.

Signed-off-by: Jin Yan <jinyan12@huawei.com>
---
  src/qemu/qemu_hotplug.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 3954ad1109..40092b499d 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1115,6 +1115,7 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr 
driver,
              return -1;

          disk->src = NULL;
+        virDomainDiskDefFree(disk);
          return 0;
      }

-- 



Re: [PATCH] qemu: fix memleaks in qemuDomainAttachDeviceLive()
Posted by Michal Privoznik 3 years, 9 months ago
On 7/13/20 11:39 AM, Jin Yan wrote:
>  From e46e168f9767b8b291f23217fc7a62163c82eaf8 Mon Sep 17 00:00:00 2001
> From: Jin Yan <jinyan12@huawei.com>
> Date: Tue, 7 Jul 2020 21:58:52 +0800
> Subject: [PATCH] qemu: fix memleaks in qemuDomainAttachDeviceLive()
> 
> During disk hotplugging, qemuDomainAttachDeviceLive() add the new
> disk to the device list of the VM object. However, hotplugging
> cdroms and floppies only updates the src variable of the original
> disk device, so the newly generated disk object needs to be released.
> 
> Signed-off-by: Jin Yan <jinyan12@huawei.com>
> ---
>   src/qemu/qemu_hotplug.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 3954ad1109..40092b499d 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -1115,6 +1115,7 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr 
> driver,
>               return -1;
> 
>           disk->src = NULL;
> +        virDomainDiskDefFree(disk);
>           return 0;
>       }
> 

This patch is corrupted, please use git-send-email next time. But since 
the diff is trivial to apply I did the change by hand.

Nice catch! Pushed.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Congratulations on your first libvirt contribution!

Michal