1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

revision: fix leaking saved parents

The `saved_parents` slab is used by `--full-diff` to save parents of a
commit which we are about to rewrite. We do not release its contents
once it's not used anymore, causing a memory leak. Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2024-09-30 11:14:06 +02:00 committed by Junio C Hamano
parent 4cc2cee5ac
commit 6512d6e473
2 changed files with 11 additions and 2 deletions

View file

@ -4207,10 +4207,18 @@ static void save_parents(struct rev_info *revs, struct commit *commit)
*pp = EMPTY_PARENT_LIST; *pp = EMPTY_PARENT_LIST;
} }
static void free_saved_parent(struct commit_list **parents)
{
if (*parents != EMPTY_PARENT_LIST)
free_commit_list(*parents);
}
static void free_saved_parents(struct rev_info *revs) static void free_saved_parents(struct rev_info *revs)
{ {
if (revs->saved_parents_slab) if (!revs->saved_parents_slab)
clear_saved_parents(revs->saved_parents_slab); return;
deep_clear_saved_parents(revs->saved_parents_slab, free_saved_parent);
FREE_AND_NULL(revs->saved_parents_slab);
} }
struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit) struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit)

View file

@ -5,6 +5,7 @@ test_description='merge simplification'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
note () { note () {