From 5e367af7b53b95bf084ded361dfe431c66572150 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 1 Aug 2017 01:34:21 +0800 Subject: [PATCH] Fix CGBitmapContextCreate bitmap memory leak issue Pass NULL to CGBitmapContextCreate whenever the data param is not used later to reduce memory leak issue --- SDWebImage/SDWebImageDecoder.m | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/SDWebImage/SDWebImageDecoder.m b/SDWebImage/SDWebImageDecoder.m index cf5e6760..eeaac6c3 100644 --- a/SDWebImage/SDWebImageDecoder.m +++ b/SDWebImage/SDWebImageDecoder.m @@ -115,16 +115,10 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over size_t bytesPerRow = kBytesPerPixel * destResolution.width; - // Allocate enough pixel data to hold the output image. - void* destBitmapData = malloc( bytesPerRow * destResolution.height ); - if (destBitmapData == NULL) { - return image; - } - // kCGImageAlphaNone is not supported in CGBitmapContextCreate. // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast // to create bitmap graphics contexts without alpha info. - destContext = CGBitmapContextCreate(destBitmapData, + destContext = CGBitmapContextCreate(NULL, destResolution.width, destResolution.height, kBitsPerComponent, @@ -133,7 +127,6 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast); if (destContext == NULL) { - free(destBitmapData); return image; } CGContextSetInterpolationQuality(destContext, kCGInterpolationHigh);