Browse Source

Merge branch 'ma/reduce-heads-leakfix'

Leak fixes.

* ma/reduce-heads-leakfix:
  reduce_heads: fix memory leaks
  builtin/merge-base: free commit lists
maint
Junio C Hamano 7 years ago
parent
commit
905f16dd02
  1. 2
      builtin/commit.c
  2. 2
      builtin/fmt-merge-msg.c
  3. 40
      builtin/merge-base.c
  4. 1
      builtin/merge.c
  5. 5
      builtin/pull.c
  6. 7
      commit.c
  7. 18
      commit.h

2
builtin/commit.c

@ -1750,7 +1750,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) @@ -1750,7 +1750,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)

2
builtin/fmt-merge-msg.c

@ -571,7 +571,7 @@ static void find_merge_parents(struct merge_parents *result, @@ -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);

40
builtin/merge-base.c

@ -9,20 +9,20 @@ @@ -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) @@ -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;
}


1
builtin/merge.c

@ -998,6 +998,7 @@ static struct commit_list *reduce_parents(struct commit *head_commit, @@ -998,6 +998,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;

5
builtin/pull.c

@ -751,12 +751,15 @@ static int get_octopus_merge_base(struct object_id *merge_base, @@ -751,12 +751,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;
}


7
commit.c

@ -1090,6 +1090,13 @@ struct commit_list *reduce_heads(struct commit_list *heads) @@ -1090,6 +1090,13 @@ struct commit_list *reduce_heads(struct commit_list *heads)
return result;
}

void reduce_heads_replace(struct commit_list **heads)
{
struct commit_list *result = reduce_heads(*heads);
free_commit_list(*heads);
*heads = result;
}

static const char gpg_sig_header[] = "gpgsig";
static const int gpg_sig_header_len = sizeof(gpg_sig_header) - 1;


18
commit.h

@ -313,7 +313,23 @@ extern int interactive_add(int argc, const char **argv, const char *prefix, int @@ -313,7 +313,23 @@ extern int interactive_add(int argc, const char **argv, const char *prefix, int
extern int run_add_interactive(const char *revision, const char *patch_mode,
const struct pathspec *pathspec);

struct commit_list *reduce_heads(struct commit_list *heads);
/*
* Takes a list of commits and returns a new list where those
* have been removed that can be reached from other commits in
* the list. It is useful for, e.g., reducing the commits
* randomly thrown at the git-merge command and removing
* redundant commits that the user shouldn't have given to it.
*
* This function destroys the STALE bit of the commit objects'
* flags.
*/
extern struct commit_list *reduce_heads(struct commit_list *heads);

/*
* Like `reduce_heads()`, except it replaces the list. Use this
* instead of `foo = reduce_heads(foo);` to avoid memory leaks.
*/
extern void reduce_heads_replace(struct commit_list **heads);

struct commit_extra_header {
struct commit_extra_header *next;

Loading…
Cancel
Save