]> git.ipfire.org Git - thirdparty/git.git/commitdiff
revision: fix leaking parents when simplifying commits
authorPatrick Steinhardt <ps@pks.im>
Thu, 26 Sep 2024 11:47:05 +0000 (13:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Sep 2024 15:25:37 +0000 (08:25 -0700)
When simplifying commits, e.g. because they are treesame with their
parents, we unset the commit's parent pointers but never free them. Plug
the resulting memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
t/t1414-reflog-walk.sh
t/t5310-pack-bitmaps.sh
t/t5326-multi-pack-bitmaps.sh
t/t6004-rev-list-path-optim.sh
t/t6019-rev-list-ancestry-path.sh
t/t6111-rev-list-treesame.sh

index 2d7ad2bddff345703e8acc494789c280644d576c..e79f39e555560f11207aff62916bd297130c4ad7 100644 (file)
@@ -1071,7 +1071,11 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
                                        ts->treesame[nth_parent] = 1;
                                continue;
                        }
+
+                       free_commit_list(parent->next);
                        parent->next = NULL;
+                       while (commit->parents != parent)
+                               pop_commit(&commit->parents);
                        commit->parents = parent;
 
                        /*
@@ -1103,6 +1107,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
                                        die("cannot simplify commit %s (invalid %s)",
                                            oid_to_hex(&commit->object.oid),
                                            oid_to_hex(&p->object.oid));
+                               free_commit_list(p->parents);
                                p->parents = NULL;
                        }
                /* fallthrough */
index be6c3f472c176525b64383b726ad7b05b664accd..49d28166da0d93095988c959ad87842e17cc9860 100755 (executable)
@@ -4,6 +4,7 @@ test_description='various tests of reflog walk (log -g) behavior'
 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 'set up some reflog entries' '
index a6de7c5764307817cce2d4ecf9140d84aa70d448..7044c7d7c6d0bc804fb8baff48c8d3718945c018 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='exercise basic bitmap functionality'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-bitmap.sh
 
index 832b92619c06b18a850bb0b3c10f25b775d6f064..6eaa692f33b5c42bf24459377bd31309f7b03f00 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='exercise basic multi-pack bitmap functionality'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "${TEST_DIRECTORY}/lib-bitmap.sh"
 
index cd4f420e2a1e3919985a29d174055fab0f50c85f..5416241edea0a024e4566a2f61441a54eae07e66 100755 (executable)
@@ -16,6 +16,7 @@ test_description='git rev-list trivial path optimization test
 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 738da23628b12b4660105195e2bbcedf68416f33..1aabab69568a18d103db308f53a8b2e05cfe643d 100755 (executable)
@@ -29,6 +29,7 @@ test_description='--ancestry-path'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_merge () {
index 90ff14164009d0e3dcdfeaf0a41763c39d2eab23..f63bc8d3da62af61e0292991bbf0439dcd7f2d5d 100755 (executable)
@@ -16,6 +16,7 @@ test_description='TREESAME and limiting'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 note () {