builtin/merge-tree: fix leaking `-X` strategy options
The `-X` switch for git-merge-tree(1) will push each option into a local `xopts` vector that we then end up parsing. The vector never gets freed though, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Aug 22, 2024 at 11:17 UTC
ff0935b96e414ff7115f281308c33fb93e4e26ce
2 files changed
+11
-3
builtin/merge-tree.c
+10
-3
@@ -533,6 +533,7 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
533
int expected_remaining_argc;
534
int original_argc;
535
const char *merge_base = NULL;
536
+ int ret;
537
538
const char * const merge_tree_usage[] = {
539
N_("git merge-tree [--write-tree] [<options>] <branch1> <branch2>"),
@@ -625,7 +626,9 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
626
strbuf_list_free(split);
627
}
628
strbuf_release(&buf);
628
- return 0;
629
+
630
+ ret = 0;
631
+ goto out;
632
}
633
634
/* Figure out which mode to use */
@@ -664,7 +667,11 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
667
668
/* Do the relevant type of merge */
669
if (o.mode == MODE_REAL)
667
- return real_merge(&o, merge_base, argv[0], argv[1], prefix);
670
+ ret = real_merge(&o, merge_base, argv[0], argv[1], prefix);
671
else
669
- return trivial_merge(argv[0], argv[1], argv[2]);
672
+ ret = trivial_merge(argv[0], argv[1], argv[2]);
673
+
674
+out:
675
+ strvec_clear(&xopts);
676
+ return ret;
677
}
t/t4301-merge-tree-write-tree.sh
+1
@@ -2,6 +2,7 @@
2
3
test_description='git merge-tree --write-tree'
4
5
+TEST_PASSES_SANITIZE_LEAK=true
6
. ./test-lib.sh
7
8
# This test is ort-specific