[PATCHv2 2/2] xfree86: loader: use one exit code only for readability

Peter Hutterer peter.hutterer at who-t.net
Sun Apr 3 15:40:16 PDT 2011


On Thu, Mar 31, 2011 at 04:26:07PM +0300, Tiago Vignatti wrote:
> No functional changes. Spaghetti code for win! \o/
> 
> Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
> ---
>  hw/xfree86/loader/loadmod.c |   34 ++++++++++++++--------------------
>  1 files changed, 14 insertions(+), 20 deletions(-)
> 
> diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
> index 46ce68b..db8037c 100644
> --- a/hw/xfree86/loader/loadmod.c
> +++ b/hw/xfree86/loader/loadmod.c
> @@ -483,19 +483,15 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
>      char *fp;
>      char **listing = NULL;
>      char **save;
> +    char **ret = NULL;
>      int n = 0;
>  
>      if (!(pathlist = InitPathList(NULL)))
>  	return NULL;
> -    if (!(subdirs = InitSubdirs(subdirlist))) {
> -	FreePathList(pathlist);
> -	return NULL;
> -    }
> -    if (!(patterns = InitPatterns(patternlist))) {
> -	FreePathList(pathlist);
> -	FreeSubdirs(subdirs);
> -	return NULL;
> -    }
> +    if (!(subdirs = InitSubdirs(subdirlist)))
> +	goto InitSubdirs_fail;
> +    if (!(patterns = InitPatterns(patternlist)))
> +	goto InitPatterns_fail;
>  
>      for (elem = pathlist; *elem; elem++) {
>  	for (s = subdirs; *s; s++) {
> @@ -529,20 +525,14 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
>  				    save[n] = NULL;
>  				    FreeStringList(save);
>  				}
> -				FreePathList(pathlist);
> -				FreeSubdirs(subdirs);
> -				FreePatterns(patterns);
>  				closedir(d);
> -				return NULL;
> +				goto bail;
>  			    }
>  			    listing[n] = malloc(len + 1);
>  			    if (!listing[n]) {
>  				FreeStringList(listing);
> -				FreePathList(pathlist);
> -				FreeSubdirs(subdirs);
> -				FreePatterns(patterns);
>  				closedir(d);
> -				return NULL;
> +				goto bail;
>  			    }
>  			    strncpy(listing[n], dp->d_name + match[1].rm_so,
>  				    len);
> @@ -558,11 +548,15 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
>      }
>      if (listing)
>  	listing[n] = NULL;
> +    ret = listing;
>  
> -    FreePathList(pathlist);
> -    FreeSubdirs(subdirs);
> +bail:
>      FreePatterns(patterns);
> -    return listing;
> +InitPatterns_fail:
> +    FreeSubdirs(subdirs);
> +InitSubdirs_fail:
> +    FreePathList(pathlist);
> +    return ret;

FreePatterns, FreePatterns and FreeSubdirs can all handle NULL, suggesting
that we don't need 3 labels but only one.

Cheers,
  Peter

>  }
>  
>  void
> -- 
> 1.7.0.4
> 
> 


More information about the xorg-devel mailing list