Re: [PATCH] esx: Simplify goto usage (part 1/2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/26/2010 10:30 AM, Matthias Bolte wrote:
> Eliminate almost all backward jumps by replacing this common pattern:
> 
> int
> some_random_function(void)
> {
>     int result = 0;
>     ...
> 
>   cleanup:
>     <unconditional cleanup code>
>     return result;
> 
>   failure:
>     <cleanup code in case of an error>
>     result = -1;
>     goto cleanup
> }
> 
> with this simpler pattern:
> 
> int
> some_random_function(void)
> {
>     int result = -1;
>     ...
>     result = 0;
> 
>   cleanup:
>     if (result < 0) {
>         <cleanup code in case of an error>
>     }
> 
>     <unconditional cleanup code>
>     return result;
> }

Mostly mechanical, according to that pattern.

> @@ -1786,21 +1733,17 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
>          esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
>                                           propertyNameList, &virtualMachine,
>                                           esxVI_Occurrence_RequiredItem) < 0) {
> -        goto failure;
> +        goto cleanup;
>      }
>  
>      info->state = VIR_DOMAIN_NOSTATE;
> -    info->maxMem = 0;
> -    info->memory = 0;
> -    info->nrVirtCpu = 0;
> -    info->cpuTime = 0; /* FIXME */

I didn't quite follow this deletion just from the patch itself; are
these values not valid if info->state is VIR_DOMAIN_NOSTATE?

> @@ -2219,6 +2158,10 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
>      }
>  
>    cleanup:
> +    if (url == NULL) {
> +        virBufferFreeAndReset(&buffer);
> +    }
> +
>      esxVI_String_Free(&propertyNameList);
>      esxVI_ObjectContent_Free(&virtualMachine);
>      VIR_FREE(datastoreName);
> @@ -2229,12 +2172,6 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
>      virDomainDefFree(def);
>  
>      return xml;
> -
> -  failure:
> -    virBufferFreeAndReset(&buffer);
> -    VIR_FREE(xml);

Did we lose a VIR_FREE(xml) on this conversion?  Or can we guarantee
that xml is NULL if url is NULL?

ACK, assuming you can either answer those questions or tweak the code to
fix them.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]