@@ -1476,14 +1476,23 @@ static int run_apply(const struct am_state *state, const char *index_file)
1476
1476
int res , opts_left ;
1477
1477
int force_apply = 0 ;
1478
1478
int options = 0 ;
1479
+ const char * * apply_argv ;
1479
1480
1480
1481
if (init_apply_state (& apply_state , the_repository , NULL ))
1481
1482
BUG ("init_apply_state() failed" );
1482
1483
1483
1484
strvec_push (& apply_opts , "apply" );
1484
1485
strvec_pushv (& apply_opts , state -> git_apply_opts .v );
1485
1486
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 ,
1487
1496
& apply_state , & force_apply , & options ,
1488
1497
NULL );
1489
1498
@@ -1513,6 +1522,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
1513
1522
strvec_clear (& apply_paths );
1514
1523
strvec_clear (& apply_opts );
1515
1524
clear_apply_state (& apply_state );
1525
+ free (apply_argv );
1516
1526
1517
1527
if (res )
1518
1528
return res ;
0 commit comments