Skip to content

Commit 7ac5eca

Browse files
committed
Merge branch 'rs/am-parse-options-cleanup' into maint-2.39
Code clean-up. * rs/am-parse-options-cleanup: am: don't pass strvec to apply_parse_options()
2 parents b7a7af2 + a658e88 commit 7ac5eca

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

builtin/am.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,14 +1476,23 @@ static int run_apply(const struct am_state *state, const char *index_file)
14761476
int res, opts_left;
14771477
int force_apply = 0;
14781478
int options = 0;
1479+
const char **apply_argv;
14791480

14801481
if (init_apply_state(&apply_state, the_repository, NULL))
14811482
BUG("init_apply_state() failed");
14821483

14831484
strvec_push(&apply_opts, "apply");
14841485
strvec_pushv(&apply_opts, state->git_apply_opts.v);
14851486

1486-
opts_left = apply_parse_options(apply_opts.nr, apply_opts.v,
1487+
/*
1488+
* Build a copy that apply_parse_options() can rearrange.
1489+
* apply_opts.v keeps referencing the allocated strings for
1490+
* strvec_clear() to release.
1491+
*/
1492+
ALLOC_ARRAY(apply_argv, apply_opts.nr);
1493+
COPY_ARRAY(apply_argv, apply_opts.v, apply_opts.nr);
1494+
1495+
opts_left = apply_parse_options(apply_opts.nr, apply_argv,
14871496
&apply_state, &force_apply, &options,
14881497
NULL);
14891498

@@ -1513,6 +1522,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
15131522
strvec_clear(&apply_paths);
15141523
strvec_clear(&apply_opts);
15151524
clear_apply_state(&apply_state);
1525+
free(apply_argv);
15161526

15171527
if (res)
15181528
return res;

0 commit comments

Comments
 (0)