]> git.ipfire.org Git - thirdparty/git.git/commit
commit: fix "author_ident" leak
authorJunio C Hamano <gitster@pobox.com>
Thu, 12 May 2022 22:51:07 +0000 (15:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 May 2022 22:51:32 +0000 (15:51 -0700)
commit00d8c311050824f841617e954c641ec2ebb300ec
tree53d5869ad8619e62e36cebda58ee4bd9f00adfa5
parent4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a
commit: fix "author_ident" leak

Since 4c28e4ada03 (commit: die before asking to edit the log
message, 2010-12-20), we have been "leaking" the "author_ident" when
prepare_to_commit() fails.  Instead of returning from right there,
introduce an exit status variable and jump to the clean-up label
at the end.

Instead of explicitly releasing the resource with strbuf_release(),
mark the variable with UNLEAK() at the end, together with two other
variables that are already marked as such.  If this were in a
utility function that is called number of times, but these are
different, we should explicitly release resources that grow
proportionally to the size of the problem being solved, but
cmd_commit() is like main() and there is no point in spending extra
cycles to release individual pieces of resource at the end, just
before process exit will clean everything for us for free anyway.

This fixes a leak demonstrated by e.g. "t3505-cherry-pick-empty.sh",
but unfortunately we cannot mark it or other affected tests as passing
now with "TEST_PASSES_SANITIZE_LEAK=true" as we'll need to fix many
other memory leaks before doing so.

Incidentally there are two tests that always passes the leak checker
with or without this change.  Mark them as such.

This is based on an earlier patch by Ævar, but takes a different
approach that is more maintainable.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c
t/t2203-add-intent.sh
t/t7011-skip-worktree-reading.sh