Skip to content

Commit

Permalink
merge-base: free() allocated "struct commit **" list
Browse files Browse the repository at this point in the history
Fix a memory leak in 53eda89 (merge-base: teach "git merge-base"
to drive underlying merge_bases_many(), 2008-07-30) by calling free()
on the "struct commit **" list used by "git merge-base".

This gets e.g. "t6010-merge-base.sh" closer to passing under
SANITIZE=leak, it failed 8 tests before when compiled with that
option, and now fails only 5 tests.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
avar authored and gitster committed Mar 4, 2022
1 parent f2bcc69 commit e69fe2e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion builtin/merge-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
int rev_nr = 0;
int show_all = 0;
int cmdmode = 0;
int ret;

struct option options[] = {
OPT_BOOL('a', "all", &show_all, N_("output all common ancestors")),
Expand Down Expand Up @@ -186,5 +187,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
ALLOC_ARRAY(rev, argc);
while (argc-- > 0)
rev[rev_nr++] = get_commit_reference(*argv++);
return show_merge_base(rev, rev_nr, show_all);
ret = show_merge_base(rev, rev_nr, show_all);
free(rev);
return ret;
}

0 comments on commit e69fe2e

Please sign in to comment.