Skip to content

Commit 4cc2cee

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d4855e commit 4cc2cee

6 files changed

+7
-0
lines changed

revision.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,7 @@ static int remove_duplicate_parents(struct rev_info *revs, struct commit *commit
32503250
struct commit *parent = p->item;
32513251
if (parent->object.flags & TMP_MARK) {
32523252
*pp = p->next;
3253+
free(p);
32533254
if (ts)
32543255
compact_treesame(revs, commit, surviving_parents);
32553256
continue;
@@ -4005,6 +4006,7 @@ int rewrite_parents(struct rev_info *revs, struct commit *commit,
40054006
break;
40064007
case rewrite_one_noparents:
40074008
*pp = parent->next;
4009+
free(parent);
40084010
continue;
40094011
case rewrite_one_error:
40104012
return -1;

t/t3427-rebase-subtree.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This test runs git rebase and tests the subtree strategy.
77
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
88
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
99

10+
TEST_PASSES_SANITIZE_LEAK=true
1011
. ./test-lib.sh
1112
. "$TEST_DIRECTORY"/lib-rebase.sh
1213

t/t6016-rev-list-graph-simplify-history.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test_description='--graph and simplified history'
1010
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1111
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1212

13+
TEST_PASSES_SANITIZE_LEAK=true
1314
. ./test-lib.sh
1415
. "$TEST_DIRECTORY"/lib-log-graph.sh
1516

t/t7003-filter-branch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='git filter-branch'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89
. "$TEST_DIRECTORY/lib-gpg.sh"
910

t/t9350-fast-export.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_description='git fast-export'
77
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
88
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
99

10+
TEST_PASSES_SANITIZE_LEAK=true
1011
. ./test-lib.sh
1112

1213
test_expect_success 'setup' '

t/t9402-git-cvsserver-refs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tags, branches and other git refspecs'
88
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010

11+
TEST_PASSES_SANITIZE_LEAK=true
1112
. ./test-lib.sh
1213

1314
#########

0 commit comments

Comments
 (0)