diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-06-11 11:19:50 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-06-11 13:15:05 -0700 |
| commit | f644dc84949bcc6d6d06274a30feb4b366ae68de (patch) | |
| tree | 575d800735a9687ed89c1e0f7c4c33a91382c0ce | |
| parent | 97485374377fa62fdd36f4b707e2fcd8f1a7c6c3 (diff) | |
| download | git-f644dc84949bcc6d6d06274a30feb4b366ae68de.tar.gz | |
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>
| -rw-r--r-- | notes.c | 7 | ||||
| -rwxr-xr-x | t/t3306-notes-prune.sh | 1 |
2 files changed, 7 insertions, 1 deletions
@@ -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; } } diff --git a/t/t3306-notes-prune.sh b/t/t3306-notes-prune.sh index 8f4102ff9e..b6e9f643e3 100755 --- a/t/t3306-notes-prune.sh +++ b/t/t3306-notes-prune.sh @@ -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' ' |
