git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
René Scharfe <l.s.r@web.de>
Date
Sep 7, 2022, 06:01 UTC
Message-ID
<3a2609e3-453a-441b-346d-dcc2877d159f@web.de>
In-Reply-To
<a3e73848-4262-1875-5ba1-085d31297933@web.de>
Am 06.09.22 um 14:31 schrieb René Scharfe:
Show 5 quoted lines
> 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@gmx.de>
Show 42 quoted lines
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  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
Previous: René ScharfeNext: René Scharfe
Message 6 of 17 in “unleak paths allocated in "diff --no-index"”
  1. unleak paths allocated in "diff --no-index"Junio C Hamano, Sep 2, 2022
  2. diff --no-index: unleak paths[] elementsJunio C Hamano, Sep 2, 2022
  3. René ScharfeSep 3, 2022
  4. Junio C HamanoSep 5, 2022
  5. 1/2 diff-no-index: release strbuf on queue errorRené Scharfe, Sep 6, 2022
  6. René ScharfeSep 7, 2022
  7. 2/2 diff-no-index: release prefixed filenamesRené Scharfe, Sep 6, 2022
  8. Johannes SchindelinSep 7, 2022
  9. René ScharfeSep 7, 2022
  10. 1/2 diff-no-index: release strbuf on queue errorRené Scharfe, Sep 7, 2022
  11. 2/2 diff-no-index: release prefixed filenamesRené Scharfe, Sep 7, 2022
  12. 3/2 diff-no-index: simplify argv index calculationRené Scharfe, Sep 7, 2022
  13. Junio C HamanoSep 7, 2022
  14. Johannes SchindelinSep 5, 2022
  15. Ævar Arnfjörð BjarmasonSep 5, 2022
  16. Johannes SchindelinSep 7, 2022
  17. Ævar Arnfjörð BjarmasonSep 7, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.