]> git.ipfire.org Git - thirdparty/git.git/commit
commit: fix leaking parents when calling `commit_tree_extended()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Jun 2024 09:20:42 +0000 (11:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2024 20:15:07 +0000 (13:15 -0700)
commit63c9bd372e388f5fed77be56771d5ad972f37f8e
tree70f1e32515bb7b1142f310ef9995a30e19859044
parentc6eb58bfb19a0840841934b91613ea53f0da8651
commit: fix leaking parents when calling `commit_tree_extended()`

When creating commits via `commit_tree_extended()`, the caller passes in
a string list of parents. This call implicitly transfers ownership of
that list to the function, which is quite surprising to begin with. But
to make matters worse, `commit_tree_extended()` doesn't even bother to
free the list of parents in error cases. The result is a memory leak,
and one that the caller cannot fix by themselves because they do not
know whether parts of the string list have already been released.

Refactor the code such that callers can keep ownership of the list of
parents, which is getting indicated by parameter being a constant
pointer now. Free the lists at the calling site and add a common exit
path to those sites as required.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 files changed:
builtin/am.c
builtin/commit-tree.c
builtin/commit.c
builtin/merge.c
builtin/replay.c
builtin/stash.c
commit.c
commit.h
notes-merge.c
notes-utils.c
notes-utils.h
sequencer.c
t/t3403-rebase-skip.sh
t/t3424-rebase-empty.sh
t/t3505-cherry-pick-empty.sh
t/t7505-prepare-commit-msg-hook.sh