]> git.ipfire.org Git - thirdparty/git.git/commitdiff
revision: fix leaking saved parents
authorPatrick Steinhardt <ps@pks.im>
Mon, 30 Sep 2024 09:14:06 +0000 (11:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2024 18:23:07 +0000 (11:23 -0700)
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>
revision.c
t/t6012-rev-list-simplify.sh

index 6b452ea18222932f121b5c897eae75d8156982bf..f5f5b84f2b083657bcc98950b5c294314e52d37a 100644 (file)
@@ -4207,10 +4207,18 @@ static void save_parents(struct rev_info *revs, struct commit *commit)
                *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)
 {
-       if (revs->saved_parents_slab)
-               clear_saved_parents(revs->saved_parents_slab);
+       if (!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)
index de1e87f1621d5db8c3730662731fdd67e1dffba7..8ed1a215da68ffa042ca44dfd4a4521bee153e47 100755 (executable)
@@ -5,6 +5,7 @@ test_description='merge simplification'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 note () {