]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/log: fix leaking commit list in git-cherry(1)
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Jun 2024 09:20:19 +0000 (11:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2024 20:15:06 +0000 (13:15 -0700)
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>
builtin/log.c
t/t3500-cherry.sh

index 37ecb3ff8b93324a2aaee5a17d467b15fa41be76..b36fa9d1550dc0e1762919efcbf9a63202e1183b 100644 (file)
@@ -2675,16 +2675,16 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
                commit_list_insert(commit, &list);
        }
 
-       while (list) {
+       for (struct commit_list *l = list; l; l = l->next) {
                char sign = '+';
 
-               commit = list->item;
+               commit = l->item;
                if (has_commit_patch_id(commit, &ids))
                        sign = '-';
                print_commit(sign, commit, verbose, abbrev, revs.diffopt.file);
-               list = list->next;
        }
 
+       free_commit_list(list);
        free_patch_ids(&ids);
        return 0;
 }
index 78c3eac54b599ef9cded9a042f4346621798b645..61ca87512d59dcc37a831619cb6691af97fa7d25 100755 (executable)
@@ -11,6 +11,7 @@ checks that git cherry only returns the second patch in the local branch
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 GIT_AUTHOR_EMAIL=bogus_email_address