Skip to content

Commit

Permalink
Objective-C: Fix memory leak in Patch (google#156)
Browse files Browse the repository at this point in the history
Resolves google#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 <atdrendel@users.noreply.github.com>
  • Loading branch information
atdrendel authored and dmsnell committed Mar 22, 2024
1 parent e54c85b commit 5337709
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 5337709

Please sign in to comment.