]> git.ipfire.org Git - thirdparty/git.git/commitdiff
notes: fix memory leak when pruning notes
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Jun 2024 09:19:50 +0000 (11:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2024 20:15:05 +0000 (13:15 -0700)
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>
notes.c
t/t3306-notes-prune.sh

diff --git a/notes.c b/notes.c
index 6a157e34ce610379e9c7cdf466a44083c186629f..244b5c4b1c06b7fa0e3f4c63f981da0085fd6504 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -1219,11 +1219,16 @@ void prune_notes(struct notes_tree *t, int flags)
        for_each_note(t, 0, prune_notes_helper, &l);
 
        while (l) {
+               struct note_delete_list *next;
+
                if (flags & NOTES_PRUNE_VERBOSE)
                        printf("%s\n", hash_to_hex(l->sha1));
                if (!(flags & NOTES_PRUNE_DRYRUN))
                        remove_note(t, l->sha1);
-               l = l->next;
+
+               next = l->next;
+               free(l);
+               l = next;
        }
 }
 
index 8f4102ff9e446bce66436b5e7046c84d739c226f..b6e9f643e3cd8d4a81d63e721c5a16390b879e05 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='Test git notes prune'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup: create a few commits with notes' '