Re: [PATCH 1/2] diff-no-index: release strbuf on queue error

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

 



Am 06.09.22 um 14:31 schrieb René Scharfe:
> The strbuf is small and we are about to exit, so we could leave its
> cleanup to the OS.  If we release it explicitly at all, however, then we
> should do it on early exit as well.  Move it to a new cleanup section at
> the end and make sure all execution paths go through it.
>

Oh, forgot:

Suggested-by: Johannes Schindelin <johannes.schindelin@xxxxxx>

> Signed-off-by: René Scharfe <l.s.r@xxxxxx>
> ---
>  diff-no-index.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index 9a8b09346b..a3683d8a04 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -243,6 +243,7 @@ int diff_no_index(struct rev_info *revs,
>  		  int argc, const char **argv)
>  {
>  	int i, no_index;
> +	int ret = 1;
>  	const char *paths[2];
>  	struct strbuf replacement = STRBUF_INIT;
>  	const char *prefix = revs->prefix;
> @@ -295,16 +296,18 @@ int diff_no_index(struct rev_info *revs,
>  	revs->diffopt.flags.exit_with_status = 1;
>
>  	if (queue_diff(&revs->diffopt, paths[0], paths[1]))
> -		return 1;
> +		goto out;
>  	diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
>  	diffcore_std(&revs->diffopt);
>  	diff_flush(&revs->diffopt);
>
> -	strbuf_release(&replacement);
> -
>  	/*
>  	 * The return code for --no-index imitates diff(1):
>  	 * 0 = no changes, 1 = changes, else error
>  	 */
> -	return diff_result_code(&revs->diffopt, 0);
> +	ret = diff_result_code(&revs->diffopt, 0);
> +
> +out:
> +	strbuf_release(&replacement);
> +	return ret;
>  }
> --
> 2.37.2




[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]

  Powered by Linux