[PATCH 08/29] notes: fix memory leak when pruning notes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 notes.c                | 7 ++++++-
 t/t3306-notes-prune.sh | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/notes.c b/notes.c
index 6a157e34ce..244b5c4b1c 100644
--- 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;
 	}
 }
 
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' '
-- 
2.45.1.410.g58bac47f8e.dirty

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux