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

Re: [PATCH] apply: plug strbuf leak

From
Junio C Hamano <gitster@pobox.com>
Date
May 20, 2026, 06:48 UTC
Message-ID
<xmqqtss237b8.fsf@gitster.g>
In-Reply-To
<xmqq33zm4msa.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 25 quoted lines
> Depending on how read_patch_file() fails, it may already have read
> many bytes into the supplied strbuf.  Either the caller or the callee
> should release the strbuf.
>
> Here we choose to make the sole caller of the function responsible
> for releasing it, as it makes the error handling slightly simpler.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  apply.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/apply.c b/apply.c
> index 4aa1694cfa..0167902325 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -4881,8 +4881,10 @@ static int apply_patch(struct apply_state *state,
>  
>  	state->patch_input_file = filename;
>  	state->linenr = 1;
> -	if (read_patch_file(&buf, fd) < 0)
> +	if (read_patch_file(&buf, fd) < 0) {
> +		strbuf_release(&buf);
>  		return -128;
> +	}

Ah, my mistake. This was one of the two "oh, we found longstanding issues immediately after enabling EXPENSIVE tests on" fixes Peff already fixed for us.

>  	offset = 0;
>  	while (offset < buf.len) {
>  		struct patch *patch;
Previous: Junio C Hamano
Message 2 of 2 in “apply: plug strbuf leak”
  1. apply: plug strbuf leakJunio C Hamano, May 20, 2026
  2. Junio C HamanoMay 20, 2026

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.