Fix the potential leak for SDAnimatedImageRep image source

This commit is contained in:
DreamPiggy 2019-06-05 17:09:00 +08:00
parent ba39cec210
commit a7a866b706
1 changed files with 8 additions and 6 deletions

View File

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