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

Michal Privoznik mprivozn at redhat.com
Thu Sep 19 14:46:25 UTC 2019


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 at 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 at redhat.com>

Michal




More information about the libvir-list mailing list