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

Re: [PATCH] builtin/apply: free patch when parse_chunk() fails

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 1, 2016, 17:23 UTC
Message-ID
<xmqqr3epi6pd.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1458156911-26649-1-git-send-email-chriscool@tuxfamily.org>
Christian Couder <christian.couder@gmail.com> writes:
Show 10 quoted lines
> When parse_chunk() fails it can return -1, for example
> when find_header() doesn't find a patch header.
>
> In this case it's better in apply_patch() to free the
> "struct patch" that we just allocated instead of
> leaking it.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  builtin/apply.c | 4 +++-
OK.  Will queue.  Thanks.
Show 18 quoted lines
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/apply.c b/builtin/apply.c
> index 42c610e..bf78282 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -4373,8 +4373,10 @@ static int apply_patch(int fd, const char *filename, int options)
>  		patch->inaccurate_eof = !!(options & INACCURATE_EOF);
>  		patch->recount =  !!(options & RECOUNT);
>  		nr = parse_chunk(buf.buf + offset, buf.len - offset, patch);
> -		if (nr < 0)
> +		if (nr < 0) {
> +			free_patch(patch);
>  			break;
> +		}
>  		if (apply_in_reverse)
>  			reverse_patches(patch);
>  		if (use_patch(patch)) {
Previous: Christian Couder
Message 5 of 5 in “builtin/apply: free patch when parse_chunk() fails”
  1. builtin/apply: free patch when parse_chunk() failsChristian Couder, Mar 16, 2016
  2. Christian CouderMar 31, 2016
  3. Junio C HamanoMar 31, 2016
  4. Christian CouderMar 31, 2016
  5. Junio C HamanoApr 1, 2016

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.