Skip to content

Commit f644dc8

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

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

notes.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,11 +1219,16 @@ void prune_notes(struct notes_tree *t, int flags)
12191219
for_each_note(t, 0, prune_notes_helper, &l);
12201220

12211221
while (l) {
1222+
struct note_delete_list *next;
1223+
12221224
if (flags & NOTES_PRUNE_VERBOSE)
12231225
printf("%s\n", hash_to_hex(l->sha1));
12241226
if (!(flags & NOTES_PRUNE_DRYRUN))
12251227
remove_note(t, l->sha1);
1226-
l = l->next;
1228+
1229+
next = l->next;
1230+
free(l);
1231+
l = next;
12271232
}
12281233
}
12291234

t/t3306-notes-prune.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='Test git notes prune'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_expect_success 'setup: create a few commits with notes' '

0 commit comments

Comments
 (0)