revision: fix leaking parents when simplifying commits

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>

Patrick Steinhardt committed Sep 26, 2024 at 13:47 UTC fa016423c748cd142a40c10eb7f9cc4c4fffbb98
7 files changed +12
revision.c
+5
@@ -1071,7 +1071,11 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
1071 ts->treesame[nth_parent] = 1;
1072 continue;
1073 }
1074 +
1075 + free_commit_list(parent->next);
1076 parent->next = NULL;
1077 + while (commit->parents != parent)
1078 + pop_commit(&commit->parents);
1079 commit->parents = parent;
1080
1081 /*
@@ -1103,6 +1107,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
1107 die("cannot simplify commit %s (invalid %s)",
1108 oid_to_hex(&commit->object.oid),
1109 oid_to_hex(&p->object.oid));
1110 + free_commit_list(p->parents);
1111 p->parents = NULL;
1112 }
1113 /* fallthrough */
t/t1414-reflog-walk.sh
+1
@@ -4,6 +4,7 @@ test_description='various tests of reflog walk (log -g) behavior'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 +TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 test_expect_success 'set up some reflog entries' '
t/t5310-pack-bitmaps.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='exercise basic bitmap functionality'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-bitmap.sh
8
t/t5326-multi-pack-bitmaps.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='exercise basic multi-pack bitmap functionality'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "${TEST_DIRECTORY}/lib-bitmap.sh"
8
t/t6004-rev-list-path-optim.sh
+1
@@ -16,6 +16,7 @@ test_description='git rev-list trivial path optimization test
16 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
17 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18
19 +TEST_PASSES_SANITIZE_LEAK=true
20 . ./test-lib.sh
21
22 test_expect_success setup '
t/t6019-rev-list-ancestry-path.sh
+1
@@ -29,6 +29,7 @@ test_description='--ancestry-path'
29 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
30 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
31
32 +TEST_PASSES_SANITIZE_LEAK=true
33 . ./test-lib.sh
34
35 test_merge () {
t/t6111-rev-list-treesame.sh
+1
@@ -16,6 +16,7 @@ test_description='TREESAME and limiting'
16 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
17 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18
19 +TEST_PASSES_SANITIZE_LEAK=true
20 . ./test-lib.sh
21
22 note () {