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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 11, 2024 at 11:19 UTC 56931c4d89e7efe41dd96d230b8176e2d32a035d
2 files changed +2
revision.c
+1
@@ -4430,6 +4430,7 @@ struct commit *get_revision(struct rev_info *revs)
4430 reversed = NULL;
4431 while ((c = get_revision_internal(revs)))
4432 commit_list_insert(c, &reversed);
4433 + free_commit_list(revs->commits);
4434 revs->commits = reversed;
4435 revs->reverse = 0;
4436 revs->reverse_output_stage = 1;
t/t3508-cherry-pick-many-commits.sh
+1
@@ -5,6 +5,7 @@ test_description='test cherry-picking many commits'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 check_head_differs_from() {