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

[PATCH 4/4] setup: fix leaking repository format

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 6, 2023, 10:46 UTC
Message-ID
<1bbddbcb0b0b91128b9ddec69d8374c92e9128d5.1699267422.git.ps@pks.im>
In-Reply-To
<cover.1699267422.git.ps@pks.im>

While populating the `repository_format` structure may cause us to allocate memory, we do not call `clear_repository_format()` in some places and thus potentially leak memory. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 setup.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/setup.c b/setup.c
index b9474b163a0..fc592dc6dd5 100644
--- a/setup.c
+++ b/setup.c
@@ -722,6 +722,7 @@ int upgrade_repository_format(int target_version)
 	ret = 1;
 
 out:
+	clear_repository_format(&repo_fmt);
 	strbuf_release(&repo_version);
 	strbuf_release(&err);
 	return ret;
@@ -2199,6 +2200,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
 	}
 
+	clear_repository_format(&repo_fmt);
 	free(original_git_dir);
 	return 0;
 }
-- 
2.42.0
Previous: Patrick SteinhardtNext: Jeff King
Message 7 of 9 in “Memory leak fixes”
  1. 0/4 Memory leak fixesPatrick Steinhardt, Nov 6, 2023
  2. 1/4 test-bloom: stop setting up Git directory twicePatrick Steinhardt, Nov 6, 2023
  3. Jeff KingNov 6, 2023
  4. 2/4 shallow: fix memory leak when registering shallow rootsPatrick Steinhardt, Nov 6, 2023
  5. Jeff KingNov 6, 2023
  6. 3/4 setup: refactor `upgrade_repository_format()` to have common exitPatrick Steinhardt, Nov 6, 2023
  7. 4/4 setup: fix leaking repository formatPatrick Steinhardt, Nov 6, 2023
  8. Jeff KingNov 6, 2023
  9. Junio C HamanoNov 7, 2023

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.