Skip to content

Commit 6512d6e

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4cc2cee commit 6512d6e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

revision.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,10 +4207,18 @@ static void save_parents(struct rev_info *revs, struct commit *commit)
42074207
*pp = EMPTY_PARENT_LIST;
42084208
}
42094209

4210+
static void free_saved_parent(struct commit_list **parents)
4211+
{
4212+
if (*parents != EMPTY_PARENT_LIST)
4213+
free_commit_list(*parents);
4214+
}
4215+
42104216
static void free_saved_parents(struct rev_info *revs)
42114217
{
4212-
if (revs->saved_parents_slab)
4213-
clear_saved_parents(revs->saved_parents_slab);
4218+
if (!revs->saved_parents_slab)
4219+
return;
4220+
deep_clear_saved_parents(revs->saved_parents_slab, free_saved_parent);
4221+
FREE_AND_NULL(revs->saved_parents_slab);
42144222
}
42154223

42164224
struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit)

t/t6012-rev-list-simplify.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='merge simplification'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
note () {

0 commit comments

Comments
 (0)