[PATCH 20/55] hyperv: use g_autoptr for WMI classes in hypervDomainGetMaxMemory

Laine Stump laine at redhat.com
Fri Jan 22 08:15:25 UTC 2021


On 1/21/21 1:51 PM, Matt Coleman wrote:
> Signed-off-by: Matt Coleman <matt at datto.com>
> ---
>   src/hyperv/hyperv_driver.c | 17 +++++------------
>   1 file changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 7da4c216b1..2ec0415f62 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -1860,25 +1860,18 @@ hypervDomainGetMaxMemory(virDomainPtr domain)
>   {
>       char uuid_string[VIR_UUID_STRING_BUFLEN];
>       hypervPrivate *priv = domain->conn->privateData;
> -    Msvm_VirtualSystemSettingData *vssd = NULL;
> -    Msvm_MemorySettingData *mem_sd = NULL;
> -    int maxMemoryBytes = 0;
> +    g_autoptr(Msvm_VirtualSystemSettingData) vssd = NULL;
> +    g_autoptr(Msvm_MemorySettingData) mem_sd = NULL;
>   
>       virUUIDFormat(domain->uuid, uuid_string);
>   
>       if (hypervGetMsvmVirtualSystemSettingDataFromUUID(priv, uuid_string, &vssd) < 0)
> -        goto cleanup;
> +        return 0;
>   
>       if (hypervGetMemorySD(priv, vssd->data->InstanceID, &mem_sd) < 0)
> -        goto cleanup;
> -
> -    maxMemoryBytes = mem_sd->data->Limit * 1024;
> -
> - cleanup:
> -    hypervFreeObject((hypervObject *)vssd);
> -    hypervFreeObject((hypervObject *)mem_sd);
> +        return 0;
>   
> -    return maxMemoryBytes;
> +    return mem_sd->data->Limit * 1024;


Another case where the return value is being retrieved from an 
auto-freed object. Might be right, but I want to verify it with someone 
who knows (or examination of the generated assembly code in gdb)


>   }
>   
>   





More information about the libvir-list mailing list