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

[PATCH 3/9] test-tool {dump,scrap}-cache-tree: fix memory leaks

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 30, 2022, 23:47 UTC
Message-ID
<patch-3.9-7a0064860ad-20220630T180129Z-avarab@gmail.com>
In-Reply-To
<cover-0.9-00000000000-20220630T180129Z-avarab@gmail.com>

Fix memory leaks in two test-tools used by t0090-cache-tree.sh. As a result we can mark the test as passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-dump-cache-tree.c  | 7 ++++++-
 t/helper/test-scrap-cache-tree.c | 1 +
 t/t0090-cache-tree.sh            | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 6a3f88f5f5d..0d6d7f1ecbf 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -59,11 +59,16 @@ int cmd__dump_cache_tree(int ac, const char **av)
 {
 	struct index_state istate;
 	struct cache_tree *another = cache_tree();
+	int ret;
+
 	setup_git_directory();
 	if (read_cache() < 0)
 		die("unable to read index file");
 	istate = the_index;
 	istate.cache_tree = another;
 	cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
-	return dump_cache_tree(active_cache_tree, another, "");
+	ret = dump_cache_tree(active_cache_tree, another, "");
+	cache_tree_free(&another);
+
+	return ret;
 }
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 393f1604ff9..026c802479d 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -12,6 +12,7 @@ int cmd__scrap_cache_tree(int ac, const char **av)
 	hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
 	if (read_cache() < 0)
 		die("unable to read index file");
+	cache_tree_free(&active_cache_tree);
 	active_cache_tree = NULL;
 	if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
 		die("unable to write index file");
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 90675726484..d8e2fc42e15 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -5,6 +5,8 @@ test_description="Test whether cache-tree is properly updated
 Tests whether various commands properly update and/or rewrite the
 cache-tree extension.
 "
+
+TEST_PASSES_SANITIZE_LEAK=true
  . ./test-lib.sh
 
 cmp_cache_tree () {
-- 
2.37.0.874.g7d3439f13c4
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 2 of 26 in “test-tool: fix memory leaks”
  1. 0/9 test-tool: fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  2. 3/9 test-tool {dump,scrap}-cache-tree: fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  3. 2/9 test-tool path-utils: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  4. Eric SunshineJul 1, 2022
  5. Ævar Arnfjörð BjarmasonJul 1, 2022
  6. 1/9 test-tool test-hash: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  7. 8/9 test-tool ref-store: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  8. 4/9 test-tool urlmatch-normalization: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  9. 5/9 test-tool regex: call regfree(), fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  10. Junio C HamanoJul 1, 2022
  11. 7/9 test-tool bloom: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  12. Eric SunshineJul 1, 2022
  13. Ævar Arnfjörð BjarmasonJul 1, 2022
  14. 9/9 test-tool delta: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  15. 6/9 test-tool json-writer: fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  16. 0/9 test-tool: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  17. 1/9 test-tool test-hash: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  18. 2/9 test-tool path-utils: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  19. Junio C HamanoJul 1, 2022
  20. 3/9 test-tool {dump,scrap}-cache-tree: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  21. 4/9 test-tool urlmatch-normalization: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  22. 5/9 test-tool regex: call regfree(), fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  23. 6/9 test-tool json-writer: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  24. 7/9 test-tool bloom: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  25. 8/9 test-tool ref-store: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  26. 9/9 test-tool delta: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022

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.