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

[PATCH v2 1/1] Don't free remote->name after fetch

From
Kkmcguigan@twopensource.com <kmcguigan@twopensource.com>
Date
Jun 14, 2016, 18:28 UTC
Message-ID
<1465928936-68866-1-git-send-email-kmcguigan@twopensource.com>
From: Keith McGuigan <kmcguigan@twopensource.com>

Make fetch's string_list of remote names owns all of its string items (strdup'ing when necessary) so that it can deallocate them safely when clearing.

---
 builtin/fetch.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 630ae6a1bb78..1b4e924bd222 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1071,7 +1071,7 @@ static int get_remote_group(const char *key, const char *value, void *priv)
 			size_t wordlen = strcspn(value, " \t\n");
 
 			if (wordlen >= 1)
-				string_list_append(g->list,
+				string_list_append_nodup(g->list,
 						   xstrndup(value, wordlen));
 			value += wordlen + (value[wordlen] != '\0');
 		}
@@ -1261,7 +1261,7 @@ done:
 int cmd_fetch(int argc, const char **argv, const char *prefix)
 {
 	int i;
-	struct string_list list = STRING_LIST_INIT_NODUP;
+	struct string_list list = STRING_LIST_INIT_DUP;
 	struct remote *remote;
 	int result = 0;
 	struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
@@ -1347,8 +1347,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 		argv_array_clear(&options);
 	}
 
-	/* All names were strdup()ed or strndup()ed */
-	list.strdup_strings = 1;
 	string_list_clear(&list, 0);
 
 	close_all_packs();
-- 
2.8.0.rc3.94.g2dc3105.dirty
Next: Junio C Hamano
Message 1 of 4 in “Don't free remote->name after fetch”
  1. 1/1 Don't free remote->name after fetchkmcguigan@twopensource.com, Jun 14, 2016
  2. Junio C HamanoJun 14, 2016
  3. Keith McGuiganJun 14, 2016
  4. Junio C HamanoJun 14, 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.