Skip to content

Commit

Permalink
When we allocate objects in a given zone, we are not guaranteed to ge…
Browse files Browse the repository at this point in the history
…t back something actually allocated in that zone (eg the runtime might use a common heap) so if we are creating/destroying other heap memory based on zone we need to make sure we are consistently using the same zone info.
  • Loading branch information
rfm committed Nov 16, 2024
1 parent 87e132c commit f7fd33a
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions Source/NSBezierPath.m
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,21 @@ - (id) init

- (void) dealloc
{
if (_pathElements != NULL)
if (_pathElements)
{
GSIArrayEmpty(_pathElements);
NSZoneFree([self zone], _pathElements);
}

if (_cacheImage != nil)
RELEASE(_cacheImage);
if (_cacheImage)
{
RELEASE(_cacheImage);
}

if (_dash_pattern != NULL)
NSZoneFree([self zone], _dash_pattern);
if (_dash_pattern)
{
NSZoneFree([self zone], _dash_pattern);
}

[super dealloc];
}
Expand Down Expand Up @@ -2069,22 +2073,36 @@ - (id)initWithCoder:(NSCoder *)aCoder
//
// NSCopying Protocol
//
- (id)copyWithZone:(NSZone *)zone
- (id) copyWithZone: (NSZone *)zone
{
NSBezierPath *path = (NSBezierPath*)NSCopyObject (self, 0, zone);
NSBezierPath *path = (NSBezierPath*)NSCopyObject(self, 0, zone);

/* Get the zone actually usd by the copy so we can use it consistently.
*/
zone = [path zone];

if (_cachesBezierPath && _cacheImage)
path->_cacheImage = [_cacheImage copy];
{
// FIXME ... should this retain rather than copy?
path->_cacheImage = [_cacheImage copyWithZone: zone];
}
else
{
path->_cacheImage = nil;
}

if (_dash_pattern != NULL)
if (_dash_pattern)
{
CGFloat *pattern = NSZoneMalloc(zone, _dash_count * sizeof(CGFloat));

memcpy(pattern, _dash_pattern, _dash_count * sizeof(CGFloat));
_dash_pattern = pattern;
path->_dash_pattern = pattern;
}

path->_pathElements = GSIArrayCopyWithZone(_pathElements, zone);
if (_pathElements)
{
path->_pathElements = GSIArrayCopyWithZone(_pathElements, zone);
}

return path;
}
Expand Down

0 comments on commit f7fd33a

Please sign in to comment.