Re: [PATCH 1/5] check-ref-format: Refactor out check_one_ref_format

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

 



On 11/04/2016 08:13 PM, Ian Jackson wrote:
> We are going to want to reuse this.  No functional change right now.
> 
> It currently has a hidden memory leak if --normalize is used.
> 
> Signed-off-by: Ian Jackson <ijackson@xxxxxxxxxxxxxxxxxxxxxx>
> ---
>  builtin/check-ref-format.c | 26 ++++++++++++++------------
>  1 file changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
> index eac4994..4d56caa 100644
> --- a/builtin/check-ref-format.c
> +++ b/builtin/check-ref-format.c
> @@ -48,12 +48,22 @@ static int check_ref_format_branch(const char *arg)
>  	return 0;
>  }
>  
> +static int normalize = 0;
> +static int flags = 0;
> +
> +static int check_one_ref_format(const char *refname)
> +{
> +	if (normalize)
> +		refname = collapse_slashes(refname);
> +	if (check_refname_format(refname, flags))
> +		return 1;
> +	if (normalize)
> +		printf("%s\n", refname);

This function needs to `return 0` if it gets to the end.

> +}
> +
>  int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
>  {
>  	int i;
> -	int normalize = 0;
> -	int flags = 0;
> -	const char *refname;
>  
>  	if (argc == 2 && !strcmp(argv[1], "-h"))
>  		usage(builtin_check_ref_format_usage);
> @@ -76,13 +86,5 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
>  	if (! (i == argc - 1))
>  		usage(builtin_check_ref_format_usage);
>  
> -	refname = argv[i];
> -	if (normalize)
> -		refname = collapse_slashes(refname);
> -	if (check_refname_format(refname, flags))
> -		return 1;
> -	if (normalize)
> -		printf("%s\n", refname);
> -
> -	return 0;
> +	return check_one_ref_format(argv[i]);
>  }
> 

Michael




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]