Skip to content

Commit

Permalink
Memleak fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed May 14, 2015
1 parent a578322 commit 21d0487
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
3 changes: 3 additions & 0 deletions pxSVG/pxSVGLayer.m
Expand Up @@ -60,6 +60,7 @@ - (void)loadURL:(NSURL *)url
if ([op isCancelled]) return;
if (!weakself) return;
weakself.loadOperation = nil;
op = nil;
NSError *error = err;
if (!error && [resp isKindOfClass:[NSHTTPURLResponse class]] && (((NSHTTPURLResponse*)resp).statusCode != 200))
error = [NSError errorWithDomain:@"pxSVGLoader.httpStatus" code:((NSHTTPURLResponse*)resp).statusCode userInfo:nil];
Expand Down Expand Up @@ -91,6 +92,7 @@ - (void)loadString:(NSString *)string
if ([op isCancelled]) return;
if (!weakself) return;
weakself.parseOperation = nil;
op = nil;
if (!img) return [weakself loadError:[NSError errorWithDomain:@"pxSVGParser.parseError" code:0 userInfo:nil]];
[weakself loadImage:img];
}];
Expand All @@ -112,6 +114,7 @@ - (void)loadImage:(pxSVGImage*)image
if (!weakself) return;
[weakself addSublayer:img];
weakself.parseOperation = nil;
op = nil;
weakself.contentRect = image.bounds;
if ([weakself.svgDelegate respondsToSelector:@selector(svgLayerDidLoadImage:)])
[weakself.svgDelegate svgLayerDidLoadImage:weakself];
Expand Down
14 changes: 1 addition & 13 deletions pxSVG/pxSVGRenderPath.m
Expand Up @@ -11,7 +11,6 @@
#import "pxSVGPath.h"

@interface pxSVGGradient : NSObject
@property CGGradientRef gradient;
@property NSArray *colors;
@property NSArray *locations;
@property CGPoint startPoint, endPoint;
Expand Down Expand Up @@ -195,21 +194,18 @@ - (pxSVGGradient*)parseLinearGradient:(pxXMLNode*)node
if (!gid) return nil;
NSString *href = [node.attributes objectForKey:@"xlink:href"];
if (!href) href = [node.attributes objectForKey:@"href"];
CGGradientRef gr;
CGPoint sp = CGPointZero, ep = (CGPoint){INFINITY,INFINITY};
NSMutableArray *cls, *locs;
if (href) {
href = [href substringFromIndex:1];
pxSVGGradient *g = (id)[self findDef:href];
if (![g isKindOfClass:[pxSVGGradient class]]) return nil;
gr = g.gradient;
sp = g.startPoint;
ep = g.endPoint;
cls = (id)g.colors;
locs = (id)g.locations;
} else {
cls = [NSMutableArray new], locs = [NSMutableArray new];
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
for (pxXMLNode *s in node.childNodes) {
if (![s.tagName isEqualToString:@"stop"]) {
NSLog(@"Unknown gradient node: %@",s);
Expand All @@ -232,21 +228,13 @@ - (pxSVGGradient*)parseLinearGradient:(pxXMLNode*)node
[locs addObject:@([[ma objectForKey:@"offset"] doubleValue])];
}
}
CGFloat *locs_a = CFAllocatorAllocate(CFAllocatorGetDefault(), (sizeof(CGFloat)*locs.count), 0);
for (NSUInteger i=0; i<locs.count; i++) {
locs_a[i] = [locs[i] doubleValue];
}
gr = CGGradientCreateWithColors(cs, (__bridge CFArrayRef)cls, locs_a);
CFAllocatorDeallocate(CFAllocatorGetDefault(), locs_a);
CGColorSpaceRelease(cs);
}
if ([node.attributes objectForKey:@"x1"]) sp.x = [[node.attributes objectForKey:@"x1"] doubleValue];
if ([node.attributes objectForKey:@"y1"]) sp.y = [[node.attributes objectForKey:@"y1"] doubleValue];
if ([node.attributes objectForKey:@"x2"]) ep.x = [[node.attributes objectForKey:@"x2"] doubleValue];
if ([node.attributes objectForKey:@"y2"]) ep.y = [[node.attributes objectForKey:@"y2"] doubleValue];
if (gr) {
if (cls.count) {
pxSVGGradient *g = [pxSVGGradient new];
g.gradient = gr;
g.colors = cls;
g.locations = locs;
g.startPoint = sp;
Expand Down

0 comments on commit 21d0487

Please sign in to comment.