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>
This commit is contained in:

committed by
Junio C Hamano

parent
6a09c3a9a6
commit
9ff2f06069
@ -251,6 +251,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
|
||||
if (opts.revs)
|
||||
release_revisions(opts.revs);
|
||||
free(opts.revs);
|
||||
replay_opts_release(&opts);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -267,5 +268,6 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
|
||||
free(opts.revs);
|
||||
if (res < 0)
|
||||
die(_("cherry-pick failed"));
|
||||
replay_opts_release(&opts);
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user