builtin/log: fix leaking commit list in git-cherry(1)

We're storing the list of commits that git-cherry(1) is about to print into a temporary list. This list is never getting free'd and thus leaks. 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:20 UTC a282dbeba718db156678aadec6c47ba1d9f13d0f
2 files changed +4 -3
builtin/log.c
+3 -3
@@ -2675,16 +2675,16 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
2675 commit_list_insert(commit, &list);
2676 }
2677
2678 - while (list) {
2678 + for (struct commit_list *l = list; l; l = l->next) {
2679 char sign = '+';
2680
2681 - commit = list->item;
2681 + commit = l->item;
2682 if (has_commit_patch_id(commit, &ids))
2683 sign = '-';
2684 print_commit(sign, commit, verbose, abbrev, revs.diffopt.file);
2685 - list = list->next;
2685 }
2686
2687 + free_commit_list(list);
2688 free_patch_ids(&ids);
2689 return 0;
2690 }
t/t3500-cherry.sh
+1
@@ -11,6 +11,7 @@ checks that git cherry only returns the second patch in the local branch
11 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13
14 +TEST_PASSES_SANITIZE_LEAK=true
15 . ./test-lib.sh
16
17 GIT_AUTHOR_EMAIL=bogus_email_address