From a7a866b7067f94db010cdbd63c2bed56710dc424 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 5 Jun 2019 17:09:00 +0800 Subject: [PATCH] Fix the potential leak for SDAnimatedImageRep image source --- SDWebImage/SDAnimatedImageRep.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/SDWebImage/SDAnimatedImageRep.m b/SDWebImage/SDAnimatedImageRep.m index 57b3d62c..88d2384d 100644 --- a/SDWebImage/SDAnimatedImageRep.m +++ b/SDWebImage/SDAnimatedImageRep.m @@ -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