summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-08-07 14:48:00 -0700
committerJunio C Hamano <gitster@pobox.com>2026-08-07 14:48:01 -0700
commitaa2932aedde6b1fb40cdab6176f69ab9409bf2ae (patch)
tree25b55a278d194b61db3a8b216f7498f991399812
parent93a85701abaa03790133c8a87529a726ae9bee36 (diff)
parent68cce04a028cac13fa1fd7a368801fac3d8b156b (diff)
Merge branch 'tc/merge-default-to-upstream-leakfix'
A memory leak in 'git merge' when run without arguments (which triggers the default-to-upstream path) has been fixed. A test has been added to cover this case. * tc/merge-default-to-upstream-leakfix: merge: fix leak with merge.defaultToUpstream
-rw-r--r--builtin/merge.c7
-rwxr-xr-xt/t7600-merge.sh17
2 files changed, 22 insertions, 2 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index 58d1b7bb07..5b4eb23a83 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1373,7 +1373,7 @@ int cmd_merge(int argc,
struct commit_list *common = NULL;
const char *best_strategy = NULL, *wt_strategy = NULL;
struct commit_list *remoteheads = NULL, *p;
- void *branch_to_free;
+ void *branch_to_free, *argv_to_free = NULL;
int orig_argc = argc;
int merge_log_config = -1;
@@ -1517,8 +1517,10 @@ int cmd_merge(int argc,
option_commit = 1;
if (!argc) {
- if (default_to_upstream)
+ if (default_to_upstream) {
argc = setup_with_upstream(&argv);
+ argv_to_free = argv;
+ }
else
die(_("No commit specified and merge.defaultToUpstream not set."));
} else if (argc == 1 && !strcmp(argv[0], "-")) {
@@ -1880,6 +1882,7 @@ done:
}
strbuf_release(&buf);
free(branch_to_free);
+ free(argv_to_free);
free(pull_twohead);
free(pull_octopus);
discard_index(the_repository->index);
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 7f2a1db16d..e31d261f9d 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -1166,4 +1166,21 @@ test_expect_success 'suggested names are not ambiguous' '
test_grep remotes/origin/not-local stderr
'
+test_expect_success 'merge with no argument defaults to upstream' '
+ test_when_finished "rm -rf upstream downstream" &&
+ git init upstream &&
+ (
+ cd upstream &&
+ test_commit one &&
+ test_commit two
+ ) &&
+ git clone upstream downstream &&
+ (
+ cd downstream &&
+ git reset --hard HEAD^ &&
+ git merge &&
+ test_cmp_rev origin/main HEAD
+ )
+'
+
test_done