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

Re: [BUG?] git range-diff -Ix @{1}... segfaults

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 7, 2021, 20:05 UTC
Message-ID
<xmqq7dfsb18n.fsf@gitster.g>
In-Reply-To
<7ac58fa9-f0f3-53bc-e51b-de9cd4efdb29@web.de>
René Scharfe <l.s.r@web.de> writes:
> range-diff.c::output() calls diff.c::diff_flush() in a loop with the
> same struct diff_options (via range-diff.c::patch_diff()).
Woooo, that's, eh, unexpected.
> So the second iteration of that loop tries to use the already freed
> ignore regexes.  Here's a patch for that:
Thanks.
Show 11 quoted lines
>
> --- >8 ---
> Subject: [PATCH] range-diff: avoid segfault with -I
>
> output() reuses the same struct diff_options for multiple calls of
> diff_flush().  Set the option no_free to instruct it to keep the
> ignore regexes between calls and release them explicitly at the end.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> Test missing because I couldn't see any effect of -I on range-diff.

I wanted to omit my sign-off when comparing a previous series and the new series (iow, I expected -I"^Signed-off-by: me" to apply to the outer diff, not the inner "generation of patches to be compared").

Show 26 quoted lines
>  range-diff.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/range-diff.c b/range-diff.c
> index e731525e66..cac89a2f4f 100644
> --- a/range-diff.c
> +++ b/range-diff.c
> @@ -482,6 +482,7 @@ static void output(struct string_list *a, struct string_list *b,
>  	else
>  		diff_setup(&opts);
>
> +	opts.no_free = 1;
>  	if (!opts.output_format)
>  		opts.output_format = DIFF_FORMAT_PATCH;
>  	opts.flags.suppress_diff_headers = 1;
> @@ -542,6 +543,8 @@ static void output(struct string_list *a, struct string_list *b,
>  	strbuf_release(&buf);
>  	strbuf_release(&dashes);
>  	strbuf_release(&indent);
> +	opts.no_free = 0;
> +	diff_free(&opts);
>  }
>
>  int show_range_diff(const char *range1, const char *range2,
> --
> 2.33.0
Previous: René Scharfe
Message 3 of 3 in “[BUG?] git range-diff -Ix @{1}... segfaults”
  1. Junio C HamanoSep 3, 2021
  2. René ScharfeSep 4, 2021
  3. Junio C HamanoSep 7, 2021

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.