]> git.ipfire.org Git - thirdparty/git.git/commit - sequencer.c
sequencer API users: fix get_replay_opts() leaks
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 6 Feb 2023 19:08:08 +0000 (20:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Feb 2023 00:03:52 +0000 (16:03 -0800)
commit9ff2f0606915cf76fc4865bddf639fd5fd2cba29
tree148786a6b70ef1df91d9e08bc77dfad6169c4f11
parent6a09c3a9a69fa2059383dd94294bbfd44b440d4b
sequencer API users: fix get_replay_opts() leaks

Make the replay_opts_release() function added in the preceding commit
non-static, and use it for freeing the "struct replay_opts"
constructed for "rebase" and "revert".

To safely call our new replay_opts_release() we'll need to stop
calling it in sequencer_remove_state(), and instead call it where we
allocate the "struct replay_opts" itself.

This is because in e.g. do_interactive_rebase() we construct a "struct
replay_opts" with "get_replay_opts()", and then call
"complete_action()". If we get far enough in that function without
encountering errors we'll call "pick_commits()" which (indirectly)
calls sequencer_remove_state() at the end.

But if we encounter errors anywhere along the way we'd punt out early,
and not free() the memory we allocated. Remembering whether we
previously called sequencer_remove_state() would be a hassle.

Using a FREE_AND_NULL() pattern would also work, as it would be safe
to call replay_opts_release() repeatedly. But let's fix this properly
instead, by having the owner of the data free() it.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
19 files changed:
builtin/rebase.c
builtin/revert.c
sequencer.c
sequencer.h
t/t3405-rebase-malformed.sh
t/t3412-rebase-root.sh
t/t3419-rebase-patch-id.sh
t/t3423-rebase-reword.sh
t/t3425-rebase-topology-merges.sh
t/t3437-rebase-fixup-options.sh
t/t3438-rebase-broken-files.sh
t/t3501-revert-cherry-pick.sh
t/t3502-cherry-pick-merge.sh
t/t3503-cherry-pick-root.sh
t/t3506-cherry-pick-ff.sh
t/t3511-cherry-pick-x.sh
t/t7402-submodule-rebase.sh
t/t9106-git-svn-commit-diff-clobber.sh
t/t9164-git-svn-dcommit-concurrent.sh