From 60a0b3dd0ec556c28f54a299c2d44aaefb30e974 Mon Sep 17 00:00:00 2001 From: Anthony Drendel Date: Tue, 19 Mar 2024 23:31:24 +0100 Subject: [PATCH] Objective-C: Fix memory leak in Patch (google/diff-match-patch#156) Resolves google/diff-match-patch#156. The NSMutableArray being assigned to Patch.diffs isn't being autoreleased correctly. Since it's being assigned to a synthesized property marked with retain, and the NSMutableArray is being initialized with alloc-init, the array needs to be autoreleased so that it doesn't leak. See also Simperium/simperium-ios#89 Authored-by: Anthony Drendel --- objectivec/DiffMatchPatch.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objectivec/DiffMatchPatch.m b/objectivec/DiffMatchPatch.m index 0c56201..b6ebf88 100755 --- a/objectivec/DiffMatchPatch.m +++ b/objectivec/DiffMatchPatch.m @@ -189,7 +189,7 @@ - (id)copyWithZone:(NSZone *)zone { Patch *newPatch = [[[self class] allocWithZone:zone] init]; - newPatch.diffs = [[NSMutableArray alloc] initWithArray:self.diffs copyItems:YES]; + newPatch.diffs = [[[NSMutableArray alloc] initWithArray:self.diffs copyItems:YES] autorelease]; newPatch.start1 = self.start1; newPatch.start2 = self.start2; newPatch.length1 = self.length1;