notes: fix memory leak when pruning notes

In `prune_notes()` we first store the notes that are to be deleted in a
local list, and then iterate through that list to delete those notes one
by one. We never free the list though and thus leak its memory. Fix
this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2024-06-11 11:19:50 +02:00 committed by Junio C Hamano
parent 9748537437
commit f644dc8494
2 changed files with 7 additions and 1 deletions

View file

@ -1219,11 +1219,16 @@ void prune_notes(struct notes_tree *t, int flags)
for_each_note(t, 0, prune_notes_helper, &l); for_each_note(t, 0, prune_notes_helper, &l);
while (l) { while (l) {
struct note_delete_list *next;
if (flags & NOTES_PRUNE_VERBOSE) if (flags & NOTES_PRUNE_VERBOSE)
printf("%s\n", hash_to_hex(l->sha1)); printf("%s\n", hash_to_hex(l->sha1));
if (!(flags & NOTES_PRUNE_DRYRUN)) if (!(flags & NOTES_PRUNE_DRYRUN))
remove_note(t, l->sha1); remove_note(t, l->sha1);
l = l->next;
next = l->next;
free(l);
l = next;
} }
} }

View file

@ -2,6 +2,7 @@
test_description='Test git notes prune' test_description='Test git notes prune'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
test_expect_success 'setup: create a few commits with notes' ' test_expect_success 'setup: create a few commits with notes' '