summaryrefslogtreecommitdiff
path: root/builtin/merge-base.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-11-15 03:14:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-15 03:14:32 (GMT)
commit905f16dd02bb15e0c1e12bf1a6c28510f504f441 (patch)
tree30ca8d7c2c929bf8bd57d4a853e4c92e74ae1ddb /builtin/merge-base.c
parent093048b22913be23fe45635e8723d3aa3a185ff3 (diff)
parent4da72644b768b0491110a8ba0aa84d32b6bde41c (diff)
downloadgit-905f16dd02bb15e0c1e12bf1a6c28510f504f441.zip
git-905f16dd02bb15e0c1e12bf1a6c28510f504f441.tar.gz
git-905f16dd02bb15e0c1e12bf1a6c28510f504f441.tar.bz2
Merge branch 'ma/reduce-heads-leakfix'
Leak fixes. * ma/reduce-heads-leakfix: reduce_heads: fix memory leaks builtin/merge-base: free commit lists
Diffstat (limited to 'builtin/merge-base.c')
-rw-r--r--builtin/merge-base.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index e99f540..3b76001 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -9,20 +9,20 @@
static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
{
- struct commit_list *result;
+ struct commit_list *result, *r;
result = get_merge_bases_many_dirty(rev[0], rev_nr - 1, rev + 1);
if (!result)
return 1;
- while (result) {
- printf("%s\n", oid_to_hex(&result->item->object.oid));
+ for (r = result; r; r = r->next) {
+ printf("%s\n", oid_to_hex(&r->item->object.oid));
if (!show_all)
- return 0;
- result = result->next;
+ break;
}
+ free_commit_list(result);
return 0;
}
@@ -51,45 +51,47 @@ static struct commit *get_commit_reference(const char *arg)
static int handle_independent(int count, const char **args)
{
- struct commit_list *revs = NULL;
- struct commit_list *result;
+ struct commit_list *revs = NULL, *rev;
int i;
for (i = count - 1; i >= 0; i--)
commit_list_insert(get_commit_reference(args[i]), &revs);
- result = reduce_heads(revs);
- if (!result)
+ reduce_heads_replace(&revs);
+
+ if (!revs)
return 1;
- while (result) {
- printf("%s\n", oid_to_hex(&result->item->object.oid));
- result = result->next;
- }
+ for (rev = revs; rev; rev = rev->next)
+ printf("%s\n", oid_to_hex(&rev->item->object.oid));
+
+ free_commit_list(revs);
return 0;
}
static int handle_octopus(int count, const char **args, int show_all)
{
struct commit_list *revs = NULL;
- struct commit_list *result;
+ struct commit_list *result, *rev;
int i;
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;
- while (result) {
- printf("%s\n", oid_to_hex(&result->item->object.oid));
+ for (rev = result; rev; rev = rev->next) {
+ printf("%s\n", oid_to_hex(&rev->item->object.oid));
if (!show_all)
- return 0;
- result = result->next;
+ break;
}
+ free_commit_list(result);
return 0;
}