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

Re: [PATCH] send-pack: clean up extra_have oid array

From
Jeff King <peff@peff.net>
Date
Jul 3, 2025, 15:40 UTC
Message-ID
<20250703154047.GD1309870@coredump.intra.peff.net>
In-Reply-To
<xmqqzfdnkdx6.fsf@gitster.g>
On Tue, Jul 01, 2025 at 10:40:21AM -0700, Junio C Hamano wrote:
Show 32 quoted lines
> There is an early exit from the function that would bypass these
> clean-up.  Perhaps something like this on top?
> 
>  builtin/send-pack.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git c/builtin/send-pack.c w/builtin/send-pack.c
> index b28da7ddd7..6ce9f6665a 100644
> --- c/builtin/send-pack.c
> +++ w/builtin/send-pack.c
> @@ -305,9 +305,10 @@ int cmd_send_pack(int argc,
>  		flags |= MATCH_REFS_MIRROR;
>  
>  	/* match them up */
> -	if (match_push_refs(local_refs, &remote_refs, &rs, flags))
> -		return -1;
> -
> +	if (match_push_refs(local_refs, &remote_refs, &rs, flags)) {
> +		ret = -1;
> +		goto cleanup;
> +	}
>  	if (!is_empty_cas(&cas))
>  		apply_push_cas(&cas, remote, remote_refs);
>  
> @@ -340,6 +341,7 @@ int cmd_send_pack(int argc,
>  		/* stable plumbing output; do not modify or localize */
>  		fprintf(stderr, "Everything up-to-date\n");
>  
> +cleanup:
>  	string_list_clear(&push_options, 0);
>  	free_refs(remote_refs);
>  	free_refs(local_refs);

This made me wonder if the remote_refs out-parameter is valid after match_push_refs() returns failure (especially since we do not initialize it at the top of the function).

I think the answer is "yes"; it is both an in-parameter and an out-parameter, and will have been earlier set up via get_remote_heads(). So even on the failure case, match_push_refs() will leave it untouched and it is still valid (and needs to be cleaned up).

-Peff
Previous: Junio C HamanoNext: Jacob Keller
Message 7 of 9 in “send-pack: clean up extra_have oid array”
  1. send-pack: clean up extra_have oid arrayJacob Keller, Jun 27, 2025
  2. Junio C HamanoJun 30, 2025
  3. Jacob KellerJun 30, 2025
  4. Junio C HamanoJul 1, 2025
  5. Jacob KellerJul 1, 2025
  6. Junio C HamanoJul 1, 2025
  7. Jeff KingJul 3, 2025
  8. Jacob KellerJul 3, 2025
  9. Jeff KingJul 3, 2025

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.