]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-tool {dump,scrap}-cache-tree: fix memory leaks
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 1 Jul 2022 10:37:34 +0000 (12:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2022 20:38:49 +0000 (13:38 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/helper/test-dump-cache-tree.c
t/helper/test-scrap-cache-tree.c
t/t0090-cache-tree.sh

index 6a3f88f5f5d4a8af09dca7c13da6132d66093ca2..0d6d7f1ecbf198af006b4d80b8027a196d5caab3 100644 (file)
@@ -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;
 }
index 393f1604ff954703a2a5e075fbda1e14d0827dc0..026c802479d012b30bc625c820f5d0fcc25e997c 100644 (file)
@@ -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");
index 906757264844b67b0c72914b3aa2a6d02e17101c..d8e2fc42e15c73dfffebba57071b8d3e4bfd1ed1 100755 (executable)
@@ -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 () {