@@ -254,24 +254,20 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
254254
255255static int do_interactive_rebase (struct rebase_options * opts , unsigned flags )
256256{
257- int ret ;
257+ int ret = -1 ;
258258 char * revisions = NULL , * shortrevisions = NULL ;
259259 struct strvec make_script_args = STRVEC_INIT ;
260260 struct todo_list todo_list = TODO_LIST_INIT ;
261261 struct replay_opts replay = get_replay_opts (opts );
262262
263263 if (get_revision_ranges (opts -> upstream , opts -> onto , & opts -> orig_head -> object .oid ,
264264 & revisions , & shortrevisions ))
265- return -1 ;
265+ goto cleanup ;
266266
267267 if (init_basic_state (& replay ,
268268 opts -> head_name ? opts -> head_name : "detached HEAD" ,
269- opts -> onto , & opts -> orig_head -> object .oid )) {
270- free (revisions );
271- free (shortrevisions );
272-
273- return -1 ;
274- }
269+ opts -> onto , & opts -> orig_head -> object .oid ))
270+ goto cleanup ;
275271
276272 if (!opts -> upstream && opts -> squash_onto )
277273 write_file (path_squash_onto (), "%s\n" ,
@@ -300,6 +296,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
300296 opts -> autosquash , opts -> update_refs , & todo_list );
301297 }
302298
299+ cleanup :
300+ replay_opts_release (& replay );
303301 free (revisions );
304302 free (shortrevisions );
305303 todo_list_release (& todo_list );
@@ -341,6 +339,7 @@ static int run_sequencer_rebase(struct rebase_options *opts)
341339 struct replay_opts replay_opts = get_replay_opts (opts );
342340
343341 ret = sequencer_continue (the_repository , & replay_opts );
342+ replay_opts_release (& replay_opts );
344343 break ;
345344 }
346345 case ACTION_EDIT_TODO :
@@ -556,6 +555,7 @@ static int finish_rebase(struct rebase_options *opts)
556555
557556 replay .action = REPLAY_INTERACTIVE_REBASE ;
558557 ret = sequencer_remove_state (& replay );
558+ replay_opts_release (& replay );
559559 } else {
560560 strbuf_addstr (& dir , opts -> state_dir );
561561 if (remove_dir_recursively (& dir , 0 ))
@@ -1039,6 +1039,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10391039 struct string_list strategy_options = STRING_LIST_INIT_NODUP ;
10401040 struct object_id squash_onto ;
10411041 char * squash_onto_name = NULL ;
1042+ char * keep_base_onto_name = NULL ;
10421043 int reschedule_failed_exec = -1 ;
10431044 int allow_preemptive_ff = 1 ;
10441045 int preserve_merges_selected = 0 ;
@@ -1327,6 +1328,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13271328
13281329 replay .action = REPLAY_INTERACTIVE_REBASE ;
13291330 ret = sequencer_remove_state (& replay );
1331+ replay_opts_release (& replay );
13301332 } else {
13311333 strbuf_reset (& buf );
13321334 strbuf_addstr (& buf , options .state_dir );
@@ -1674,7 +1676,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
16741676 strbuf_addstr (& buf , options .upstream_name );
16751677 strbuf_addstr (& buf , "..." );
16761678 strbuf_addstr (& buf , branch_name );
1677- options .onto_name = xstrdup (buf .buf );
1679+ options .onto_name = keep_base_onto_name = xstrdup (buf .buf );
16781680 } else if (!options .onto_name )
16791681 options .onto_name = options .upstream_name ;
16801682 if (strstr (options .onto_name , "..." )) {
@@ -1848,8 +1850,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18481850 free (options .gpg_sign_opt );
18491851 string_list_clear (& options .exec , 0 );
18501852 free (options .strategy );
1853+ free (options .strategy_opts );
18511854 strbuf_release (& options .git_format_patch_opt );
18521855 free (squash_onto_name );
1856+ free (keep_base_onto_name );
18531857 string_list_clear (& strategy_options , 0 );
18541858 return !!ret ;
18551859}
0 commit comments