]> git.ipfire.org Git - thirdparty/git.git/commitdiff
revision: fix memory leak when reversing revisions
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Jun 2024 09:19:17 +0000 (11:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2024 20:15:04 +0000 (13:15 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
t/t3508-cherry-pick-many-commits.sh

index 7ddf0f151a381077c7e30d2a9835c4ec64947006..af95502d925783b5f7e8c34cbb55e6a83e4974d9 100644 (file)
@@ -4430,6 +4430,7 @@ struct commit *get_revision(struct rev_info *revs)
                reversed = NULL;
                while ((c = get_revision_internal(revs)))
                        commit_list_insert(c, &reversed);
+               free_commit_list(revs->commits);
                revs->commits = reversed;
                revs->reverse = 0;
                revs->reverse_output_stage = 1;
index 2d53ce754c5fb75ceeaa43dc1ba2f748fd58f43e..afa7727a4af8e489b8b3f36213a15ed83dc9e561 100755 (executable)
@@ -5,6 +5,7 @@ test_description='test cherry-picking many commits'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 check_head_differs_from() {