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

[PATCH 10/10] commit-graph: clear oidset after finishing write

From
Jeff King <peff@peff.net>
Date
Oct 3, 2023, 20:31 UTC
Message-ID
<20231003203130.GJ7812@coredump.intra.peff.net>
In-Reply-To
<20231003202504.GA7697@coredump.intra.peff.net>

In graph_write() we store commits in an oidset, but never clean it up, leaking the contents. We should clear it in the cleanup section.

The oidset comes from 6830c36077 (commit-graph.h: replace 'commit_hex' with 'commits', 2020-04-13), but it was just replacing a string_list that was also leaked. Curiously, we fixed the leak of some adjacent variables in commit fa8953cb40 (builtin/commit-graph.c: extract 'read_one_commit()', 2020-05-18), but the oidset wasn't included for some reason.

In combination with the preceding commits, this lets us mark t5324 as leak-free.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/commit-graph.c        | 1 +
 t/t5324-split-commit-graph.sh | 2 ++
 2 files changed, 3 insertions(+)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index c88389df24..c527a8369e 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -311,6 +311,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)
 	FREE_AND_NULL(options);
 	string_list_clear(&pack_indexes, 0);
 	strbuf_release(&buf);
+	oidset_clear(&commits);
 	return result;
 }
 
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 36c4141e67..52e8a3e619 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='split commit graph'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 GIT_TEST_COMMIT_GRAPH=0
-- 
2.42.0.810.gbc538a0ee6
Previous: Jeff KingNext: Eric W. Biederman
Message 17 of 24 in “some commit-graph leak fixes”
  1. 0/10 some commit-graph leak fixesJeff King, Oct 3, 2023
  2. 01/10 t6700: mark test as leak-freeJeff King, Oct 3, 2023
  3. Taylor BlauOct 5, 2023
  4. 02/10 commit-reach: free temporary list in get_octopus_merge_bases()Jeff King, Oct 3, 2023
  5. 03/10 merge: free result of repo_get_merge_bases()Jeff King, Oct 3, 2023
  6. Taylor BlauOct 5, 2023
  7. 04/10 commit-graph: move slab-clearing to close_commit_graph()Jeff King, Oct 3, 2023
  8. Taylor BlauOct 5, 2023
  9. 05/10 commit-graph: free all elements of graph chainJeff King, Oct 3, 2023
  10. 06/10 commit-graph: delay base_graph assignment in add_graph_to_chain()Jeff King, Oct 3, 2023
  11. Taylor BlauOct 5, 2023
  12. 07/10 commit-graph: free graph struct that was not added to chainJeff King, Oct 3, 2023
  13. 08/10 commit-graph: free write-context entries before overwritingJeff King, Oct 3, 2023
  14. Taylor BlauOct 5, 2023
  15. Jeff KingOct 5, 2023
  16. 09/10 commit-graph: free write-context base_graph_name during cleanupJeff King, Oct 3, 2023
  17. 10/10 commit-graph: clear oidset after finishing writeJeff King, Oct 3, 2023
  18. Is SANITIZE=leak make test unreliable for anyone else?Eric W. Biederman, Oct 4, 2023
  19. Jeff KingOct 4, 2023
  20. Eric W. BiedermanOct 4, 2023
  21. Jeff KingOct 4, 2023
  22. Eric W. BiedermanOct 4, 2023
  23. Taylor BlauOct 5, 2023
  24. Junio C HamanoOct 6, 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.