diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2021-10-07 11:46:09 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-10-07 15:29:02 -0700 |
commit | e5a917fcf42d2e22017ae501ffdd1c2108a1431e (patch) | |
tree | 7b8a303c53b12909fdddc8fe16de8b26a9f505e1 /check-builtins.sh | |
parent | Merge branch 'ab/sanitize-leak-ci' into ab/unpack-trees-leakfix (diff) | |
download | tgif-e5a917fcf42d2e22017ae501ffdd1c2108a1431e.tar.xz |
unpack-trees: don't leak memory in verify_clean_subdirectory()
Fix two different but related memory leaks in
verify_clean_subdirectory(). We leaked both the "pathbuf" if
read_directory() returned non-zero, and we never cleaned up our own
"struct dir_struct" either.
* "pathbuf": When the read_directory() call followed by the
free(pathbuf) was added in c81935348be (Fix switching to a branch
with D/F when current branch has file D., 2007-03-15) we didn't
bother to free() before we called die().
But when this code was later libified in 203a2fe1170 (Allow callers
of unpack_trees() to handle failure, 2008-02-07) we started to leak
as we returned data to the caller. This fixes that memory leak,
which can be observed under SANITIZE=leak with e.g. the
"t1001-read-tree-m-2way.sh" test.
* "struct dir_struct": We've leaked the dir_struct ever since this
code was added back in c81935348be.
When that commit was written there wasn't an equivalent of
dir_clear(). Since it was added in 270be816049 (dir.c: provide
clear_directory() for reclaiming dir_struct memory, 2013-01-06)
we've omitted freeing the memory allocated here.
This memory leak could also be observed under SANITIZE=leak and the
"t1001-read-tree-m-2way.sh" test.
This makes all the test in "t1001-read-tree-m-2way.sh" pass under
"GIT_TEST_PASSING_SANITIZE_LEAK=true", we'd previously die in tests
25, 26 & 28.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'check-builtins.sh')
0 files changed, 0 insertions, 0 deletions