Commit 21d0487e authored by PhoeniX's avatar PhoeniX

Memleak fixes

parent a5783227
......@@ -60,6 +60,7 @@
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];
......@@ -91,6 +92,7 @@
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];
}];
......@@ -112,6 +114,7 @@
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];
......
......@@ -11,7 +11,6 @@
#import "pxSVGPath.h"
@interface pxSVGGradient : NSObject
@property CGGradientRef gradient;
@property NSArray *colors;
@property NSArray *locations;
@property CGPoint startPoint, endPoint;
......@@ -195,21 +194,18 @@
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);
......@@ -232,21 +228,13 @@
[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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment