Skip to content

Commit

Permalink
Fix leak of image data in CGImageGetDataProvider (#1710)
Browse files Browse the repository at this point in the history
CGImageGetDataProvider was copying the CFData rather than accessing it directly, and would leak the data for consumers expecting a +0 reference.

Fixes #1709
  • Loading branch information
aballway authored Jan 18, 2017
1 parent fb59f7c commit deb99af
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 2 additions & 3 deletions Frameworks/CoreGraphics/CGImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,8 @@ - (NSUInteger)length {
CGDataProviderRef CGImageGetDataProvider(CGImageRef img) {
const UInt8* pPtr = (const UInt8*)img->Backing()->LockImageData();
CFIndex length = img->Backing()->Height() * img->Backing()->BytesPerRow();
woc::unique_cf<CFDataRef> data{ CFDataCreateWithBytesNoCopy(nullptr, pPtr, length, kCFAllocatorNull) };
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data.get());
return dataProvider;
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(nullptr, pPtr, length, nullptr);
return (CGDataProviderRef)CFAutorelease(dataProvider);
}

void* _CGImageGetData(CGImageRef img) {
Expand Down
1 change: 0 additions & 1 deletion Frameworks/ImageIO/CGImageDestination.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,6 @@ void CGImageDestinationAddImage(CGImageDestinationRef idst, CGImageRef image, CF
(unsigned char*)[imageByteData bytes],
&inputImage);
[imageByteData release];
CGDataProviderRelease(provider);
if (!SUCCEEDED(status)) {
NSTraceInfo(TAG, @"CreateBitmapFromMemory failed with status=%x\n", status);
return;
Expand Down

0 comments on commit deb99af

Please sign in to comment.