Authored by Bogdan Poplauschi
Committed by GitHub

Merge pull request #1976 from dreampiggy/fix_CGBitmapContextCreate_memory_leak

Fix CGBitmapContextCreate bitmap memory leak issue
@@ -115,16 +115,10 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over @@ -115,16 +115,10 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
115 115
116 size_t bytesPerRow = kBytesPerPixel * destResolution.width; 116 size_t bytesPerRow = kBytesPerPixel * destResolution.width;
117 117
118 - // Allocate enough pixel data to hold the output image.  
119 - void* destBitmapData = malloc( bytesPerRow * destResolution.height );  
120 - if (destBitmapData == NULL) {  
121 - return image;  
122 - }  
123 -  
124 // kCGImageAlphaNone is not supported in CGBitmapContextCreate. 118 // kCGImageAlphaNone is not supported in CGBitmapContextCreate.
125 // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast 119 // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast
126 // to create bitmap graphics contexts without alpha info. 120 // to create bitmap graphics contexts without alpha info.
127 - destContext = CGBitmapContextCreate(destBitmapData, 121 + destContext = CGBitmapContextCreate(NULL,
128 destResolution.width, 122 destResolution.width,
129 destResolution.height, 123 destResolution.height,
130 kBitsPerComponent, 124 kBitsPerComponent,
@@ -133,7 +127,6 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over @@ -133,7 +127,6 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
133 kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast); 127 kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
134 128
135 if (destContext == NULL) { 129 if (destContext == NULL) {
136 - free(destBitmapData);  
137 return image; 130 return image;
138 } 131 }
139 CGContextSetInterpolationQuality(destContext, kCGInterpolationHigh); 132 CGContextSetInterpolationQuality(destContext, kCGInterpolationHigh);