[libvirt] [PATCH] qemu_conf: clear domain before VIR_DELETE_ELEMENT

Xu Yandong posted 1 patch 4 years, 7 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1568880127-88222-1-git-send-email-xuyandong2@huawei.com
src/qemu/qemu_conf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[libvirt] [PATCH] qemu_conf: clear domain before VIR_DELETE_ELEMENT
Posted by Xu Yandong 4 years, 7 months ago
The macro VIR_DELETE_ELEMENT assume that the items being deleted have
already been cleared, so we must explicitly delete domain memory to
prevent a memory leak.

Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
---
 src/qemu/qemu_conf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 1aeec30f8a..db390d358e 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1620,10 +1620,12 @@ qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
     if (!qemuSharedDeviceEntryDomainExists(entry, name, &idx))
         return 0;
 
-    if (entry->ref != 1)
+    if (entry->ref != 1) {
+        VIR_FREE(entry->domains[idx]);
         VIR_DELETE_ELEMENT(entry->domains, idx, entry->ref);
-    else
+    } else {
         ignore_value(virHashRemoveEntry(driver->sharedDevices, key));
+    }
 
     return 0;
 }
-- 
2.18.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_conf: clear domain before VIR_DELETE_ELEMENT
Posted by Michal Privoznik 4 years, 7 months ago
On 9/19/19 10:02 AM, Xu Yandong wrote:
> The macro VIR_DELETE_ELEMENT assume that the items being deleted have
> already been cleared, so we must explicitly delete domain memory to
> prevent a memory leak.
> 
> Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
> ---
>   src/qemu/qemu_conf.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 1aeec30f8a..db390d358e 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -1620,10 +1620,12 @@ qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
>       if (!qemuSharedDeviceEntryDomainExists(entry, name, &idx))
>           return 0;
>   
> -    if (entry->ref != 1)
> +    if (entry->ref != 1) {
> +        VIR_FREE(entry->domains[idx]);
>           VIR_DELETE_ELEMENT(entry->domains, idx, entry->ref);
> -    else
> +    } else {
>           ignore_value(virHashRemoveEntry(driver->sharedDevices, key));
> +    }
>   
>       return 0;
>   }
> 

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

Michal

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