summaryrefslogtreecommitdiff
path: root/builtin/am.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-12-26 02:42:05 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-12-26 02:42:05 (GMT)
commitd8e406449aac058ff27f54f3924e1ed9da0928f4 (patch)
treeb45fd484314ad8b95d9730be742489c10350cd9a /builtin/am.c
parent7124e36ec7308edad495b821c92be9135aa6319e (diff)
parenta658e881c138c8bc398d1d4b9b6db9e29b16673c (diff)
downloadgit-d8e406449aac058ff27f54f3924e1ed9da0928f4.zip
git-d8e406449aac058ff27f54f3924e1ed9da0928f4.tar.gz
git-d8e406449aac058ff27f54f3924e1ed9da0928f4.tar.bz2
Merge branch 'rs/am-parse-options-cleanup'
Code clean-up. * rs/am-parse-options-cleanup: am: don't pass strvec to apply_parse_options()
Diffstat (limited to 'builtin/am.c')
-rw-r--r--builtin/am.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 30c9b3a..dddf1b9 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1476,6 +1476,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
int res, opts_left;
int force_apply = 0;
int options = 0;
+ const char **apply_argv;
if (init_apply_state(&apply_state, the_repository, NULL))
BUG("init_apply_state() failed");
@@ -1483,7 +1484,15 @@ static int run_apply(const struct am_state *state, const char *index_file)
strvec_push(&apply_opts, "apply");
strvec_pushv(&apply_opts, state->git_apply_opts.v);
- opts_left = apply_parse_options(apply_opts.nr, apply_opts.v,
+ /*
+ * Build a copy that apply_parse_options() can rearrange.
+ * apply_opts.v keeps referencing the allocated strings for
+ * strvec_clear() to release.
+ */
+ ALLOC_ARRAY(apply_argv, apply_opts.nr);
+ COPY_ARRAY(apply_argv, apply_opts.v, apply_opts.nr);
+
+ opts_left = apply_parse_options(apply_opts.nr, apply_argv,
&apply_state, &force_apply, &options,
NULL);
@@ -1513,6 +1522,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
strvec_clear(&apply_paths);
strvec_clear(&apply_opts);
clear_apply_state(&apply_state);
+ free(apply_argv);
if (res)
return res;