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>

Patrick Steinhardt committed Sep 30, 2024 at 11:14 UTC 6512d6e473c1c1f9f2e6967e2703a19784109a8b
2 files changed +11 -2
revision.c
+10 -2
@@ -4207,10 +4207,18 @@ static void save_parents(struct rev_info *revs, struct commit *commit)
4207 *pp = EMPTY_PARENT_LIST;
4208 }
4209
4210 +static void free_saved_parent(struct commit_list **parents)
4211 +{
4212 + if (*parents != EMPTY_PARENT_LIST)
4213 + free_commit_list(*parents);
4214 +}
4215 +
4216 static void free_saved_parents(struct rev_info *revs)
4217 {
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);
4222 }
4223
4224 struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit)
t/t6012-rev-list-simplify.sh
+1
@@ -5,6 +5,7 @@ test_description='merge simplification'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 note () {