Merge branch 'ab/sequencer-unleak'
Plug leaks in sequencer subsystem and its users. * ab/sequencer-unleak: commit.c: free() revs.commit in get_fork_point() builtin/rebase.c: free() "options.strategy_opts" sequencer.c: always free() the "msgbuf" in do_pick_commit() builtin/rebase.c: fix "options.onto_name" leak builtin/revert.c: move free-ing of "revs" to replay_opts_release() sequencer API users: fix get_replay_opts() leaks sequencer.c: split up sequencer_remove_state() rebase: use "cleanup" pattern in do_interactive_rebase()
This commit is contained in:
@ -254,7 +254,7 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
|
||||
|
||||
static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
|
||||
{
|
||||
int ret;
|
||||
int ret = -1;
|
||||
char *revisions = NULL, *shortrevisions = NULL;
|
||||
struct strvec make_script_args = STRVEC_INIT;
|
||||
struct todo_list todo_list = TODO_LIST_INIT;
|
||||
@ -262,16 +262,12 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
|
||||
|
||||
if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid,
|
||||
&revisions, &shortrevisions))
|
||||
return -1;
|
||||
goto cleanup;
|
||||
|
||||
if (init_basic_state(&replay,
|
||||
opts->head_name ? opts->head_name : "detached HEAD",
|
||||
opts->onto, &opts->orig_head->object.oid)) {
|
||||
free(revisions);
|
||||
free(shortrevisions);
|
||||
|
||||
return -1;
|
||||
}
|
||||
opts->onto, &opts->orig_head->object.oid))
|
||||
goto cleanup;
|
||||
|
||||
if (!opts->upstream && opts->squash_onto)
|
||||
write_file(path_squash_onto(), "%s\n",
|
||||
@ -300,6 +296,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
|
||||
opts->autosquash, opts->update_refs, &todo_list);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
replay_opts_release(&replay);
|
||||
free(revisions);
|
||||
free(shortrevisions);
|
||||
todo_list_release(&todo_list);
|
||||
@ -341,6 +339,7 @@ static int run_sequencer_rebase(struct rebase_options *opts)
|
||||
struct replay_opts replay_opts = get_replay_opts(opts);
|
||||
|
||||
ret = sequencer_continue(the_repository, &replay_opts);
|
||||
replay_opts_release(&replay_opts);
|
||||
break;
|
||||
}
|
||||
case ACTION_EDIT_TODO:
|
||||
@ -556,6 +555,7 @@ static int finish_rebase(struct rebase_options *opts)
|
||||
|
||||
replay.action = REPLAY_INTERACTIVE_REBASE;
|
||||
ret = sequencer_remove_state(&replay);
|
||||
replay_opts_release(&replay);
|
||||
} else {
|
||||
strbuf_addstr(&dir, opts->state_dir);
|
||||
if (remove_dir_recursively(&dir, 0))
|
||||
@ -1039,6 +1039,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
struct string_list strategy_options = STRING_LIST_INIT_NODUP;
|
||||
struct object_id squash_onto;
|
||||
char *squash_onto_name = NULL;
|
||||
char *keep_base_onto_name = NULL;
|
||||
int reschedule_failed_exec = -1;
|
||||
int allow_preemptive_ff = 1;
|
||||
int preserve_merges_selected = 0;
|
||||
@ -1327,6 +1328,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
|
||||
replay.action = REPLAY_INTERACTIVE_REBASE;
|
||||
ret = sequencer_remove_state(&replay);
|
||||
replay_opts_release(&replay);
|
||||
} else {
|
||||
strbuf_reset(&buf);
|
||||
strbuf_addstr(&buf, options.state_dir);
|
||||
@ -1674,7 +1676,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
strbuf_addstr(&buf, options.upstream_name);
|
||||
strbuf_addstr(&buf, "...");
|
||||
strbuf_addstr(&buf, branch_name);
|
||||
options.onto_name = xstrdup(buf.buf);
|
||||
options.onto_name = keep_base_onto_name = xstrdup(buf.buf);
|
||||
} else if (!options.onto_name)
|
||||
options.onto_name = options.upstream_name;
|
||||
if (strstr(options.onto_name, "...")) {
|
||||
@ -1848,8 +1850,10 @@ cleanup:
|
||||
free(options.gpg_sign_opt);
|
||||
string_list_clear(&options.exec, 0);
|
||||
free(options.strategy);
|
||||
free(options.strategy_opts);
|
||||
strbuf_release(&options.git_format_patch_opt);
|
||||
free(squash_onto_name);
|
||||
free(keep_base_onto_name);
|
||||
string_list_clear(&strategy_options, 0);
|
||||
return !!ret;
|
||||
}
|
||||
|
@ -248,9 +248,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
|
||||
res = run_sequencer(argc, argv, &opts);
|
||||
if (res < 0)
|
||||
die(_("revert failed"));
|
||||
if (opts.revs)
|
||||
release_revisions(opts.revs);
|
||||
free(opts.revs);
|
||||
replay_opts_release(&opts);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -262,10 +260,8 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
|
||||
opts.action = REPLAY_PICK;
|
||||
sequencer_init_config(&opts);
|
||||
res = run_sequencer(argc, argv, &opts);
|
||||
if (opts.revs)
|
||||
release_revisions(opts.revs);
|
||||
free(opts.revs);
|
||||
if (res < 0)
|
||||
die(_("cherry-pick failed"));
|
||||
replay_opts_release(&opts);
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user