Skip to content

Commit

Permalink
Fix memory leak in Patch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
atdrendel committed Mar 19, 2024
1 parent 62f2e68 commit 7b260d4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion objectivec/DiffMatchPatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7b260d4

Please sign in to comment.