When we allocate objects in a given zone, we are not guaranteed to get 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.

This commit is contained in:
rfm 2024-11-16 11:15:49 +00:00
parent 87e132ca82
commit f7fd33a746

View file

@ -287,17 +287,21 @@ static CGFloat default_miter_limit = 10.0;
- (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];
}
@ -2069,22 +2073,36 @@ static int winding_curve(double_point from, double_point to, double_point c1,
//
// 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;
}