revision: fix memory leaks when rewriting parents
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>
Patrick Steinhardt committed
Sep 30, 2024 at 11:14 UTC
4cc2cee5ac1491960afc54cc5ef14b50ddceb4d2
6 files changed
+7
revision.c
+2
@@ -3250,6 +3250,7 @@ static int remove_duplicate_parents(struct rev_info *revs, struct commit *commit
3250
struct commit *parent = p->item;
3251
if (parent->object.flags & TMP_MARK) {
3252
*pp = p->next;
3253
+ free(p);
3254
if (ts)
3255
compact_treesame(revs, commit, surviving_parents);
3256
continue;
@@ -4005,6 +4006,7 @@ int rewrite_parents(struct rev_info *revs, struct commit *commit,
4006
break;
4007
case rewrite_one_noparents:
4008
*pp = parent->next;
4009
+ free(parent);
4010
continue;
4011
case rewrite_one_error:
4012
return -1;
t/t3427-rebase-subtree.sh
+1
@@ -7,6 +7,7 @@ This test runs git rebase and tests the subtree strategy.
7
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10
+TEST_PASSES_SANITIZE_LEAK=true
11
. ./test-lib.sh
12
. "$TEST_DIRECTORY"/lib-rebase.sh
13
t/t6016-rev-list-graph-simplify-history.sh
+1
@@ -10,6 +10,7 @@ test_description='--graph and simplified history'
10
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
11
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12
13
+TEST_PASSES_SANITIZE_LEAK=true
14
. ./test-lib.sh
15
. "$TEST_DIRECTORY"/lib-log-graph.sh
16
t/t7003-filter-branch.sh
+1
@@ -4,6 +4,7 @@ test_description='git filter-branch'
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
. "$TEST_DIRECTORY/lib-gpg.sh"
10
t/t9350-fast-export.sh
+1
@@ -7,6 +7,7 @@ test_description='git fast-export'
7
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10
+TEST_PASSES_SANITIZE_LEAK=true
11
. ./test-lib.sh
12
13
test_expect_success 'setup' '
t/t9402-git-cvsserver-refs.sh
+1
@@ -8,6 +8,7 @@ tags, branches and other git refspecs'
8
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11
+TEST_PASSES_SANITIZE_LEAK=true
12
. ./test-lib.sh
13
14
#########