Skip to content

Commit

Permalink
This fixes a minor memory leak (detected by LeakSanitizer) in git merge.
Browse files Browse the repository at this point in the history
To reproduce (with an ASAN build):

```
mkdir test
cd test
git init
echo x > x.txt
git add .
git commit -m "WIP"
git checkout -b dev
echo y > x.txt
git add .
git commit -m "WIP"
git checkout main
echo z > x.txt
git add .
git commit -m "WIP"
echo a > x.txt
git add .
git merge dev
```

The fix is to call free_commit_list(merge_bases) when an error occurs.

Signed-off-by: Kevin Backhouse <kevinbackhouse@github.com>
  • Loading branch information
kevinbackhouse committed Aug 22, 2023
1 parent d751eee commit edf3107
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion merge-ort-wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ int merge_ort_recursive(struct merge_options *opt,
struct tree *head = repo_get_commit_tree(opt->repo, side1);
struct merge_result tmp;

if (unclean(opt, head))
if (unclean(opt, head)) {
free_commit_list(merge_bases);
return -1;
}

memset(&tmp, 0, sizeof(tmp));
merge_incore_recursive(opt, merge_bases, side1, side2, &tmp);
Expand Down
4 changes: 3 additions & 1 deletion merge-ort.c
Original file line number Diff line number Diff line change
Expand Up @@ -5070,8 +5070,10 @@ static void merge_ort_internal(struct merge_options *opt,
opt->branch1 = "Temporary merge branch 1";
opt->branch2 = "Temporary merge branch 2";
merge_ort_internal(opt, NULL, prev, next, result);
if (result->clean < 0)
if (result->clean < 0) {
free_commit_list(merge_bases);
return;
}
opt->branch1 = saved_b1;
opt->branch2 = saved_b2;
opt->priv->call_depth--;
Expand Down

0 comments on commit edf3107

Please sign in to comment.