Skip to content

Commit

Permalink
Merge branch 'en/plug-leaks-in-merge' into jch
Browse files Browse the repository at this point in the history
Leakfix.

* en/plug-leaks-in-merge:
  merge: fix memory leaks in cmd_merge()
  merge-ort: fix memory leak in merge_ort_internal()
  • Loading branch information
gitster committed Jan 27, 2022
2 parents 545926f + 6046f7a commit 3faf353
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion builtin/merge.c
Expand Up @@ -1273,7 +1273,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
struct commit_list *common = NULL;
const char *best_strategy = NULL, *wt_strategy = NULL;
struct commit_list *remoteheads, *p;
struct commit_list *remoteheads = NULL, *p;
void *branch_to_free;
int orig_argc = argc;

Expand Down Expand Up @@ -1752,6 +1752,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
ret = suggest_conflicts();

done:
if (!automerge_was_ok) {
free_commit_list(common);
free_commit_list(remoteheads);
}
strbuf_release(&buf);
free(branch_to_free);
return ret;
Expand Down
10 changes: 5 additions & 5 deletions merge-ort.c
Expand Up @@ -4579,7 +4579,7 @@ static void merge_ort_internal(struct merge_options *opt,
struct commit *h2,
struct merge_result *result)
{
struct commit_list *iter;
struct commit *next;
struct commit *merged_merge_bases;
const char *ancestor_name;
struct strbuf merge_base_abbrev = STRBUF_INIT;
Expand Down Expand Up @@ -4608,7 +4608,8 @@ static void merge_ort_internal(struct merge_options *opt,
ancestor_name = merge_base_abbrev.buf;
}

for (iter = merge_bases; iter; iter = iter->next) {
for (next = pop_commit(&merge_bases); next;
next = pop_commit(&merge_bases)) {
const char *saved_b1, *saved_b2;
struct commit *prev = merged_merge_bases;

Expand All @@ -4625,7 +4626,7 @@ static void merge_ort_internal(struct merge_options *opt,
saved_b2 = opt->branch2;
opt->branch1 = "Temporary merge branch 1";
opt->branch2 = "Temporary merge branch 2";
merge_ort_internal(opt, NULL, prev, iter->item, result);
merge_ort_internal(opt, NULL, prev, next, result);
if (result->clean < 0)
return;
opt->branch1 = saved_b1;
Expand All @@ -4636,8 +4637,7 @@ static void merge_ort_internal(struct merge_options *opt,
result->tree,
"merged tree");
commit_list_insert(prev, &merged_merge_bases->parents);
commit_list_insert(iter->item,
&merged_merge_bases->parents->next);
commit_list_insert(next, &merged_merge_bases->parents->next);

clear_or_reinit_internal_opts(opt->priv, 1);
}
Expand Down

0 comments on commit 3faf353

Please sign in to comment.