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>
Patrick Steinhardt committed
Jun 11, 2024 at 11:19 UTC
f644dc84949bcc6d6d06274a30feb4b366ae68de
2 files changed
+7
-1
notes.c
+6
-1
@@ -1219,11 +1219,16 @@ void prune_notes(struct notes_tree *t, int flags)
1219
for_each_note(t, 0, prune_notes_helper, &l);
1220
1221
while (l) {
1222
+ struct note_delete_list *next;
1223
+
1224
if (flags & NOTES_PRUNE_VERBOSE)
1225
printf("%s\n", hash_to_hex(l->sha1));
1226
if (!(flags & NOTES_PRUNE_DRYRUN))
1227
remove_note(t, l->sha1);
1226
- l = l->next;
1228
+
1229
+ next = l->next;
1230
+ free(l);
1231
+ l = next;
1232
}
1233
}
1234
t/t3306-notes-prune.sh
+1
@@ -2,6 +2,7 @@
2
3
test_description='Test git notes prune'
4
5
+TEST_PASSES_SANITIZE_LEAK=true
6
. ./test-lib.sh
7
8
test_expect_success 'setup: create a few commits with notes' '