Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing issue introduced in SVN revision 98.

  • Loading branch information...
commit b1c7b8310867a1aa21117eaac336539bc7b13c4b 1 parent 2930c1c
Jan authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 DiffMatchPatch.m
11 DiffMatchPatch.m
View
@@ -1749,6 +1749,13 @@ - (void)diff_cleanupSemantic:(NSMutableArray *)diffs;
}
[self diff_cleanupSemanticLossless:diffs];
+ // Jan: someDiff.text will NOT retain and autorelease the NSString object.
+ // This is why “prevDiff.text = ” below can cause it’s previous value to be deallocated
+ // instead of just released as one would expect without taking the above into account.
+ // Thus we need to retain its previous value before “prevDiff.text = ” and release afterwards.
+ // Alternatively, we could remove the nonatomic from the “text” @property definition.
+ // This would cause much more of a perfomance hit then warranted, though.
+
// Find any overlaps between deletions and insertions.
// e.g: <del>abcxxx</del><ins>xxxdef</ins>
// -> <del>abc</del>xxx<ins>def</ins>
@@ -1770,8 +1777,10 @@ - (void)diff_cleanupSemantic:(NSMutableArray *)diffs;
[diffs insertObject:[Diff diffWithOperation:DIFF_EQUAL
andText:[insertion substringToIndex:overlap_length1]]
atIndex:thisPointer];
+ [insertion retain];
prevDiff.text = [deletion substringToIndex:(deletion.length - overlap_length1)];
nextDiff.text = [insertion substringFromIndex:overlap_length1];
+ [insertion release];
thisPointer++;
}
} else {
@@ -1782,10 +1791,12 @@ - (void)diff_cleanupSemantic:(NSMutableArray *)diffs;
[diffs insertObject:[Diff diffWithOperation:DIFF_EQUAL
andText:[deletion substringToIndex:overlap_length2]]
atIndex:thisPointer];
+ [deletion retain];
prevDiff.operation = DIFF_INSERT;
prevDiff.text = [insertion substringToIndex:(insertion.length - overlap_length2)];
nextDiff.operation = DIFF_DELETE;
nextDiff.text = [deletion substringFromIndex:overlap_length2];
+ [deletion release];
thisPointer++;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.