Skip to content

Commit 56931c4

Browse files
pks-tgitster
authored andcommitted
revision: fix memory leak when reversing revisions
When reversing revisions in a rev walk, `get_revision()` will allocate a new commit list and assign it to `revs->commits`. It does not free the old list though, which makes it leak. Fix this. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03b0e7d commit 56931c4

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

revision.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,7 @@ struct commit *get_revision(struct rev_info *revs)
44304430
reversed = NULL;
44314431
while ((c = get_revision_internal(revs)))
44324432
commit_list_insert(c, &reversed);
4433+
free_commit_list(revs->commits);
44334434
revs->commits = reversed;
44344435
revs->reverse = 0;
44354436
revs->reverse_output_stage = 1;

t/t3508-cherry-pick-many-commits.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='test cherry-picking many commits'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
check_head_differs_from() {

0 commit comments

Comments
 (0)