ls-files: fix a --with-tree memory leak

Fix a memory leak in overlay_tree_on_index(), we need to clear_pathspec() at some point, which might as well be after the last time we use it in the function. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Ævar Arnfjörð Bjarmason committed Nov 8, 2022 at 19:17 UTC c07ce0602a7958299c7fbbf2a5b70d1510c03981
3 files changed +3 -1
builtin/ls-files.c
+1
@@ -613,6 +613,7 @@ void overlay_tree_on_index(struct index_state *istate,
613 if (!fn)
614 fn = read_one_entry_quick;
615 err = read_tree(the_repository, tree, &pathspec, fn, istate);
616 + clear_pathspec(&pathspec);
617 if (err)
618 die("unable to read tree entries %s", tree_name);
619
t/t3060-ls-files-with-tree.sh
+2
@@ -8,6 +8,8 @@ test_description='git ls-files test (--with-tree).
8 This test runs git ls-files --with-tree and in particular in
9 a scenario known to trigger a crash with some versions of git.
10 '
11 +
12 +TEST_PASSES_SANITIZE_LEAK=true
13 . ./test-lib.sh
14
15 test_expect_success 'setup' '
t/t9148-git-svn-propset.sh
-1
@@ -5,7 +5,6 @@
5
6 test_description='git svn propset tests'
7
8 -TEST_FAILS_SANITIZE_LEAK=true
8 . ./lib-git-svn.sh
9
10 test_expect_success 'setup propset via import' '