Skip to content

Commit a282dbe

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ff6bd4 commit a282dbe

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

builtin/log.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,16 +2675,16 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
26752675
commit_list_insert(commit, &list);
26762676
}
26772677

2678-
while (list) {
2678+
for (struct commit_list *l = list; l; l = l->next) {
26792679
char sign = '+';
26802680

2681-
commit = list->item;
2681+
commit = l->item;
26822682
if (has_commit_patch_id(commit, &ids))
26832683
sign = '-';
26842684
print_commit(sign, commit, verbose, abbrev, revs.diffopt.file);
2685-
list = list->next;
26862685
}
26872686

2687+
free_commit_list(list);
26882688
free_patch_ids(&ids);
26892689
return 0;
26902690
}

t/t3500-cherry.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ checks that git cherry only returns the second patch in the local branch
1111
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1212
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1313

14+
TEST_PASSES_SANITIZE_LEAK=true
1415
. ./test-lib.sh
1516

1617
GIT_AUTHOR_EMAIL=bogus_email_address

0 commit comments

Comments
 (0)