]> git.ipfire.org Git - thirdparty/git.git/commit
worktree: fix a trivial leak in prune_worktrees()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 6 Feb 2023 23:07:43 +0000 (00:07 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Feb 2023 23:34:38 +0000 (15:34 -0800)
commit9f24f3c719ccb4553f97a861c37cbedcc7357762
tree6539f045cfd6ee814ab92a03e68af8999c13eba4
parent90428ddccf7bc0c0c192fc973b2d1a7a47605e10
worktree: fix a trivial leak in prune_worktrees()

We were leaking both the "struct strbuf" in prune_worktrees(), as well
as the "path" we got from should_prune_worktree(). Since these were
the only two uses of the "struct string_list" let's change it to a
"DUP" and push these to it with "string_list_append_nodup()".

For the string_list_append_nodup() we could also string_list_append()
the main_path.buf, and then strbuf_release(&main_path) right away. But
doing it this way avoids an allocation, as we already have the "struct
strbuf" prepared for appending to "kept".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/worktree.c
t/t2401-worktree-prune.sh
t/t2406-worktree-repair.sh