]> git.ipfire.org Git - thirdparty/git.git/commitdiff
revision: fix memory leaks when rewriting parents
authorPatrick Steinhardt <ps@pks.im>
Mon, 30 Sep 2024 09:14:03 +0000 (11:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2024 18:23:07 +0000 (11:23 -0700)
Both `rewrite_parents()` and `remove_duplicate_parents()` may end up
dropping some parents from a commit without freeing the respective
`struct commit_list` items. This causes a bunch of memory leaks. Plug
these.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
t/t3427-rebase-subtree.sh
t/t6016-rev-list-graph-simplify-history.sh
t/t7003-filter-branch.sh
t/t9350-fast-export.sh
t/t9402-git-cvsserver-refs.sh

index e79f39e555560f11207aff62916bd297130c4ad7..6b452ea18222932f121b5c897eae75d8156982bf 100644 (file)
@@ -3250,6 +3250,7 @@ static int remove_duplicate_parents(struct rev_info *revs, struct commit *commit
                struct commit *parent = p->item;
                if (parent->object.flags & TMP_MARK) {
                        *pp = p->next;
+                       free(p);
                        if (ts)
                                compact_treesame(revs, commit, surviving_parents);
                        continue;
@@ -4005,6 +4006,7 @@ int rewrite_parents(struct rev_info *revs, struct commit *commit,
                        break;
                case rewrite_one_noparents:
                        *pp = parent->next;
+                       free(parent);
                        continue;
                case rewrite_one_error:
                        return -1;
index 1b3e97c8755f3d8b41549e70cf67529298118182..5e9046e3df3d5262c2845d190476b9d9bc56873e 100755 (executable)
@@ -7,6 +7,7 @@ This test runs git rebase and tests the subtree strategy.
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-rebase.sh
 
index 54b0a6f5f8a4b2996bd49ab3251837967f8fd57a..2656d6a6bc43876e8bced67343e9ec04dd8450cd 100755 (executable)
@@ -10,6 +10,7 @@ test_description='--graph and simplified history'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-log-graph.sh
 
index 5ab4d41ee7c6b122b8601bf8059eecafdf081c39..bf3e3f0b6780703e2788d672ca1fce62f175c5a8 100755 (executable)
@@ -4,6 +4,7 @@ test_description='git filter-branch'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY/lib-gpg.sh"
 
index 1eb035ee4ce547d059e07c43f04102e66ebcb000..2bdc02b4599c55339c4d5d01683d1f517e83d3c1 100755 (executable)
@@ -7,6 +7,7 @@ test_description='git fast-export'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
index 2ee41f9443eefb234dd48786f8c57d109f7dbbe3..c847120d52dd8ca4c5f7dfb8e0ccefb9a6377c7e 100755 (executable)
@@ -8,6 +8,7 @@ tags, branches and other git refspecs'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 #########