Skip to content

Commit 9afa46d

Browse files
avargitster
authored andcommitted
test-tool {dump,scrap}-cache-tree: fix memory leaks
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e287a5b commit 9afa46d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

t/helper/test-dump-cache-tree.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ int cmd__dump_cache_tree(int ac, const char **av)
5959
{
6060
struct index_state istate;
6161
struct cache_tree *another = cache_tree();
62+
int ret;
63+
6264
setup_git_directory();
6365
if (read_cache() < 0)
6466
die("unable to read index file");
6567
istate = the_index;
6668
istate.cache_tree = another;
6769
cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
68-
return dump_cache_tree(active_cache_tree, another, "");
70+
ret = dump_cache_tree(active_cache_tree, another, "");
71+
cache_tree_free(&another);
72+
73+
return ret;
6974
}

t/helper/test-scrap-cache-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int cmd__scrap_cache_tree(int ac, const char **av)
1212
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
1313
if (read_cache() < 0)
1414
die("unable to read index file");
15+
cache_tree_free(&active_cache_tree);
1516
active_cache_tree = NULL;
1617
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
1718
die("unable to write index file");

t/t0090-cache-tree.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ test_description="Test whether cache-tree is properly updated
55
Tests whether various commands properly update and/or rewrite the
66
cache-tree extension.
77
"
8+
9+
TEST_PASSES_SANITIZE_LEAK=true
810
. ./test-lib.sh
911

1012
cmp_cache_tree () {

0 commit comments

Comments
 (0)