summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorMartin Ågren <martin.agren@gmail.com>2017-11-07 20:39:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-08 02:34:00 (GMT)
commit4da72644b768b0491110a8ba0aa84d32b6bde41c (patch)
treebe9d8ddc0fc3d78e3d5aa2b80edbf396b7c2b566 /builtin
parenta452d0f4bae99c9acef6f7db75f6f1d922618732 (diff)
downloadgit-4da72644b768b0491110a8ba0aa84d32b6bde41c.zip
git-4da72644b768b0491110a8ba0aa84d32b6bde41c.tar.gz
git-4da72644b768b0491110a8ba0aa84d32b6bde41c.tar.bz2
reduce_heads: fix memory leaks
We currently have seven callers of `reduce_heads(foo)`. Six of them do not use the original list `foo` again, and actually, all six of those end up leaking it. Introduce and use `reduce_heads_replace(&foo)` as a leak-free version of `foo = reduce_heads(foo)` to fix several of these. Fix the remaining leaks using `free_commit_list()`. While we're here, document `reduce_heads()` and mark it as `extern`. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/commit.c2
-rw-r--r--builtin/fmt-merge-msg.c2
-rw-r--r--builtin/merge-base.c6
-rw-r--r--builtin/merge.c1
-rw-r--r--builtin/pull.c5
5 files changed, 11 insertions, 5 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index d75b380..11c4740 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1728,7 +1728,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
allow_fast_forward = 0;
}
if (allow_fast_forward)
- parents = reduce_heads(parents);
+ reduce_heads_replace(&parents);
} else {
if (!reflog_msg)
reflog_msg = (whence == FROM_CHERRY_PICK)
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index e99b5dd..27a2361 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -571,7 +571,7 @@ static void find_merge_parents(struct merge_parents *result,
head_commit = lookup_commit(head);
if (head_commit)
commit_list_insert(head_commit, &parents);
- parents = reduce_heads(parents);
+ reduce_heads_replace(&parents);
while (parents) {
struct commit *cmit = pop_commit(&parents);
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index e17835f..24f6c71 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -57,7 +57,7 @@ static int handle_independent(int count, const char **args)
for (i = count - 1; i >= 0; i--)
commit_list_insert(get_commit_reference(args[i]), &revs);
- revs = reduce_heads(revs);
+ reduce_heads_replace(&revs);
if (!revs)
return 1;
@@ -78,7 +78,9 @@ static int handle_octopus(int count, const char **args, int show_all)
for (i = count - 1; i >= 0; i--)
commit_list_insert(get_commit_reference(args[i]), &revs);
- result = reduce_heads(get_octopus_merge_bases(revs));
+ result = get_octopus_merge_bases(revs);
+ free_commit_list(revs);
+ reduce_heads_replace(&result);
if (!result)
return 1;
diff --git a/builtin/merge.c b/builtin/merge.c
index ab5ffe8..fbbf2a9 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -999,6 +999,7 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
/* Find what parents to record by checking independent ones. */
parents = reduce_heads(remoteheads);
+ free_commit_list(remoteheads);
remoteheads = NULL;
remotes = &remoteheads;
diff --git a/builtin/pull.c b/builtin/pull.c
index 6f772e8..4edab22 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -745,12 +745,15 @@ static int get_octopus_merge_base(struct object_id *merge_base,
if (!is_null_oid(fork_point))
commit_list_insert(lookup_commit_reference(fork_point), &revs);
- result = reduce_heads(get_octopus_merge_bases(revs));
+ result = get_octopus_merge_bases(revs);
free_commit_list(revs);
+ reduce_heads_replace(&result);
+
if (!result)
return 1;
oidcpy(merge_base, &result->item->object.oid);
+ free_commit_list(result);
return 0;
}