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

[PATCH 3/4] fetch_refs_via_pack: free extra copy of refs

From
Jeff King <peff@peff.net>
Date
Mar 19, 2015, 20:38 UTC
Message-ID
<20150319203834.GC7666@peff.net>
In-Reply-To
<20150319203126.GA31663@peff.net>

When fetch_refs_via_pack calls fetch_pack(), we pass a list of refs to fetch, and the function returns either a copy of that list, with the fetched items filled in, or NULL. We check the return value to see whether the fetch was successful, but do not otherwise look at the copy, and simply leak it at the end of the function.

Signed-off-by: Jeff King <peff@peff.net>
---
Without patch 2, this segfaults in t5516. :)
 transport.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/transport.c b/transport.c
index 0694a7c..b1953b2 100644
--- a/transport.c
+++ b/transport.c
@@ -519,7 +519,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 			       int nr_heads, struct ref **to_fetch)
 {
 	struct git_transport_data *data = transport->data;
-	const struct ref *refs;
+	struct ref *refs;
 	char *dest = xstrdup(transport->url);
 	struct fetch_pack_args args;
 	struct ref *refs_tmp = NULL;
@@ -552,15 +552,17 @@ static int fetch_refs_via_pack(struct transport *transport,
 			  &transport->pack_lockfile);
 	close(data->fd[0]);
 	close(data->fd[1]);
-	if (finish_connect(data->conn))
+	if (finish_connect(data->conn)) {
+		free_refs(refs);
 		refs = NULL;
+	}
 	data->conn = NULL;
 	data->got_remote_heads = 0;
 	data->options.self_contained_and_connected =
 		args.self_contained_and_connected;
 
 	free_refs(refs_tmp);
-
+	free_refs(refs);
 	free(dest);
 	return (refs ? 0 : -1);
 }
-- 
2.3.3.520.g3cfbb5d
Previous: Jeff KingNext: Jeff King
Message 13 of 14 in “Bug in fetch-pack.c, please confirm”
  1. Kyle J. McKayMar 15, 2015
  2. Junio C HamanoMar 15, 2015
  3. Junio C HamanoMar 15, 2015
  4. Kyle J. McKayMar 15, 2015
  5. Jeff KingMar 16, 2015
  6. Junio C HamanoMar 19, 2015
  7. Jeff KingMar 19, 2015
  8. Junio C HamanoMar 19, 2015
  9. Jeff KingMar 19, 2015
  10. 1/4 filter_ref: avoid overwriting ref->old_sha1 with garbageJeff King, Mar 19, 2015
  11. Junio C HamanoMar 19, 2015
  12. 2/4 filter_ref: make a copy of extra "sought" entriesJeff King, Mar 19, 2015
  13. 3/4 fetch_refs_via_pack: free extra copy of refsJeff King, Mar 19, 2015
  14. 4/4 fetch-pack: remove dead assignment to ref->new_sha1Jeff King, Mar 19, 2015

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.