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

[PATCH v3 5/8] Free the path_lists used to find non-local tags in git-fetch

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 3, 2008, 02:35 UTC
Message-ID
<20080303023510.GE9966@spearce.org>

To support calling find_non_local_tags() more than once in a single git-fetch process we need the existing_refs to be stack-allocated so it resets on the second call. We also should free the path lists to avoid unnecessary memory leaking.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 builtin-fetch.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 1d3ce77..3758d48 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -457,7 +457,7 @@ static void find_non_local_tags(struct transport *transport,
 			struct ref **head,
 			struct ref ***tail)
 {
-	static struct path_list existing_refs = { NULL, 0, 0, 0 };
+	struct path_list existing_refs = { NULL, 0, 0, 0 };
 	struct path_list new_refs = { NULL, 0, 0, 1 };
 	char *ref_name;
 	int ref_name_len;
@@ -503,6 +503,8 @@ static void find_non_local_tags(struct transport *transport,
 		}
 		free(ref_name);
 	}
+	path_list_clear(&existing_refs, 0);
+	path_list_clear(&new_refs, 0);
 }
 
 static int do_fetch(struct transport *transport,
-- 
1.5.4.3.468.g36990
Message 1 of 1 in “Free the path_lists used to find non-local tags in git-fetch”
  1. 5/8 Free the path_lists used to find non-local tags in git-fetchShawn O. Pearce, Mar 3, 2008

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.