Merge pull request #2746 from dreampiggy/fix_macOS_image_source_leak

Fix the potential leak for SDAnimatedImageRep image source
This commit is contained in:
Kinarobin 2019-06-05 17:39:25 +08:00 committed by GitHub
commit 9d86648419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -13,13 +13,16 @@
#import "SDImageGIFCoderInternal.h"
#import "SDImageAPNGCoderInternal.h"
@interface SDAnimatedImageRep () {
@implementation SDAnimatedImageRep {
CGImageSourceRef _imageSource;
}
@end
@implementation SDAnimatedImageRep
- (void)dealloc {
if (_imageSource) {
CFRelease(_imageSource);
_imageSource = NULL;
}
}
// `NSBitmapImageRep`'s `imageRepWithData:` is not designed initlizer
+ (instancetype)imageRepWithData:(NSData *)data {
@ -35,6 +38,7 @@
if (!imageSource) {
return self;
}
_imageSource = imageSource;
NSUInteger frameCount = CGImageSourceGetCount(imageSource);
if (frameCount <= 1) {
return self;
@ -43,8 +47,6 @@
if (!type) {
return self;
}
// Valid CGImageSource for Animated Image
_imageSource = imageSource;
if (CFStringCompare(type, kUTTypeGIF, 0) == kCFCompareEqualTo) {
// GIF
// Do nothing because NSBitmapImageRep support it