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

[PATCH v4 2/7] remote: fix tear down of struct remote

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Jun 23, 2025, 23:11 UTC
Message-ID
<20250623-jk-submodule-helper-use-url-v4-2-133ef3d89569@gmail.com>
In-Reply-To
<20250623-jk-submodule-helper-use-url-v4-0-133ef3d89569@gmail.com>
From: Jacob Keller <jacob.keller@gmail.com>

The remote_clear() function failed to free the remote->push and remote->fetch refspec fields.

This should be caught by the leak sanitizer. However, for callers which use ``the_repository``, the values never go out of scope and the sanitizer doesn't complain.

A future change is going to add a caller of read_config() for a submodule repository structure, which would result in the leak sanitizer complaining.

Fix remote_clear(), updating it to properly call refspec_clear() for both the push and fetch members.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 remote.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/remote.c b/remote.c
index ee95126f3f20080a932b82314e8017e277569cc1..194bb447784ac1f71fb85a9fed3312e7458a9d5d 100644
--- a/remote.c
+++ b/remote.c
@@ -165,6 +165,9 @@ static void remote_clear(struct remote *remote)
 	strvec_clear(&remote->url);
 	strvec_clear(&remote->pushurl);
 
+	refspec_clear(&remote->push);
+	refspec_clear(&remote->fetch);
+
 	free((char *)remote->receivepack);
 	free((char *)remote->uploadpack);
 	FREE_AND_NULL(remote->http_proxy);
-- 
2.48.1.397.gec9d649cc640
Previous: Jacob KellerNext: Jacob Keller
Message 4 of 8 in “submodule: improve remote lookup logic”
  1. 0/7 submodule: improve remote lookup logicJacob Keller, Jun 23, 2025
  2. 1/7 remote: remove branch->merge_name and fix branch_release()Jacob Keller, Jun 23, 2025
  3. 3/7 dir: move starts_with_dot(_dot)_slash to dir.hJacob Keller, Jun 23, 2025
  4. 2/7 remote: fix tear down of struct remoteJacob Keller, Jun 23, 2025
  5. 4/7 remote: remove the_repository from some functionsJacob Keller, Jun 23, 2025
  6. 5/7 submodule--helper: improve logic for fallback remote nameJacob Keller, Jun 23, 2025
  7. 6/7 submodule: move get_default_remote_submodule()Jacob Keller, Jun 23, 2025
  8. 7/7 submodule: look up remotes by URL firstJacob Keller, Jun 23, 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.