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

Eric Blake eblake at redhat.com
Wed May 26 22:13:02 UTC 2010


On 05/26/2010 10:31 AM, Matthias Bolte wrote:
> Eliminate almost all backward jumps by replacing this common pattern:
> 
> ---
> 
> I've split this 200kb patch into two 100kb parts.

More of the same mechanical changes.

>  
> +    result = 0;
> +
>    cleanup:
>      VIR_FREE(prefix);
>      VIR_FREE(deviceType);
> @@ -1666,13 +1672,12 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
>  
>      return result;
>  
> -  failure:
> -    result = -1;
> -
>    ignore:
>      virDomainDiskDefFree(*def);
>      *def = NULL;
>  
> +    result = 0;
> +
>      goto cleanup;

This looks fishy - failure used to fall through to ignore, but now you
lose the virDomainDiskDefFree.

> +    result = 0;
> +
>    cleanup:
>      VIR_FREE(connectionType);
>      VIR_FREE(addressType);
> @@ -1891,13 +1898,12 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
>  
>      return result;
>  
> -  failure:
> -    result = -1;
> -
>    ignore:
>      virDomainNetDefFree(*def);
>      *def = NULL;
>  
> +    result = 0;
> +
>      goto cleanup;

And again.

>  
> +    result = 0;
> +
>    cleanup:
>      VIR_FREE(fileType);
>      VIR_FREE(fileName);
>  
>      return result;
>  
> -  failure:
> -    result = -1;
> -
>    ignore:
>      virDomainChrDefFree(*def);
>      *def = NULL;
>  
> +    result = 0;
> +
>      goto cleanup;

And again.

>  
> +    result = 0;
> +
>    cleanup:
>      VIR_FREE(fileType);
>      VIR_FREE(fileName);
>  
>      return result;
>  
> -  failure:
> -    result = -1;
> -
>    ignore:
>      virDomainChrDefFree(*def);
>      *def = NULL;
>  
> +    result = 0;
> +
>      goto cleanup;

And again.

ACK, once you either figure out whether that idiom was safe, or fix
those four cases.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100526/a7085334/attachment-0001.sig>


More information about the libvir-list mailing list