]> git.ipfire.org Git - thirdparty/git.git/commit
grep: fix a "path_list" memory leak
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 22 Oct 2021 08:55:41 +0000 (10:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 23 Oct 2021 17:45:25 +0000 (10:45 -0700)
commitb202e51b15401207667261f2cb384e6faa6ed5c3
tree825782fe21b095928496420000043ae2554be8ac
parent96c101257b00b73f0185fc6630160a5f0b5d4277
grep: fix a "path_list" memory leak

Free the "path_list" used in builtin/grep.c, it was declared as
STRING_LIST_INIT_NODUP, let's change it to a STRING_LIST_INIT_DUP
since an early user in cmd_grep() appends a string passed via
parse-options.c to it, which needs to be duplicated.

Let's then convert the remaining callers to use
string_list_append_nodup() instead, allowing us to free the list.

This makes all the tests in t7811-grep-open.sh pass, 6/10 would fail
before this change. The only remaining failure would have been due to
a stray "git checkout" (which still leaks memory). In this case we can
use a "git reset --hard" instead, so let's do that, and move the
test_when_finished() above the code that would modify the relevant
file.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
t/t7811-grep-open.sh