Skip to content
Browse files

Merge pull request #3 from felixLam/master

Analyzer warnings
  • Loading branch information...
2 parents cde40e3 + 2678543 commit 9a34abf3ceae90db80dd0399d18cfb65fa0bc95c @peyton committed Mar 1, 2012
Showing with 19 additions and 9 deletions.
  1. +4 −2 MOOMaskedIconView/MOOCGImageWrapper.m
  2. +15 −7 MOOMaskedIconView/MOOMaskedIconView.m
View
6 MOOMaskedIconView/MOOCGImageWrapper.m
@@ -49,10 +49,12 @@ - (void)setCGImage:(CGImageRef)CGImage;
{
@synchronized(self)
{
- if (CGImage == self.CGImage)
+ if (CGImage == _CGImage)
return;
- CGImageRelease(self.CGImage);
+ if (_CGImage != NULL) {
+ CGImageRelease(_CGImage);
+ }
_CGImage = CGImageRetain(CGImage);
}
}
View
22 MOOMaskedIconView/MOOMaskedIconView.m
@@ -463,13 +463,16 @@ - (void)configureWithImageNamed:(NSString *)imageName size:(CGSize)size;
// Fetch mask if it exists
NSString *key = [imageName stringByAppendingString:NSStringFromCGSize(size)];
CGImageRef mask = CGImageRetain(((MOOCGImageWrapper *)[[[self class] defaultMaskCache] objectForKey:key]).CGImage);
- if (!mask)
- CGImageCreateMaskFromImageNamed(imageName, size);
+ if (!mask) {
+ mask = CGImageCreateMaskFromImageNamed(imageName, size);
@felixLam
felixLam added a note Mar 1, 2012

Note that I also changed this line and assigned a value to mask. I thought that this would make sense and seems plausible, but may not have enough knowledge about your code to say this with certainty. Maybe you can verify this.

@peyton
Owner
peyton added a note Mar 1, 2012

It's a typo. Thanks for spotting haha. I'll be writing tests soon to catch errors like these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
self.mask = mask;
// Cache mask
- if ([[self class] shouldCacheMaskForKey:key])
+ if ([[self class] shouldCacheMaskForKey:key]) {
[[[self class] defaultMaskCache] setObject:[MOOCGImageWrapper wrapperWithCGImage:mask] forKey:key];
+ }
+
CGImageRelease(mask);
}
@@ -827,9 +830,9 @@ - (void)_updateGradientWithColors:(NSArray *)colors locations:(NSArray *)locatio
CGImageRef CGImageCreateMaskFromCGImage(CGImageRef source, CGSize size)
{
// If no image is passed, return nothing
- if (source == nil)
+ if (source == nil) {
return NULL;
-
+ }
// Variables for image creation
CGSize imageSize = CGSizeZero;
size_t bytesPerRow = 0;
@@ -855,15 +858,20 @@ CGImageRef CGImageCreateMaskFromCGImage(CGImageRef source, CGSize size)
CGContextRelease(context);
}
else
- {
+ {
// Default size
imageSize = CGSizeMake(CGImageGetWidth(source), CGImageGetHeight(source));
bytesPerRow = CGImageGetBytesPerRow(source);
+
+ // retain source to ensure same retain count in both conditions
+ CFRetain(source);
}
// Create mask
CGImageRef maskRef = CGImageMaskCreate(imageSize.width, imageSize.height, CGImageGetBitsPerComponent(source), CGImageGetBitsPerPixel(source), bytesPerRow, CGImageGetDataProvider(source), NULL, NO);
-
+
+ // release the source as it has been retained locally
+ CFRelease(source);
return maskRef;
}

0 comments on commit 9a34abf

Please sign in to comment.
Something went wrong with that request. Please try again.