From: Ted Kremenek Date: Tue, 3 Nov 2009 05:34:07 +0000 (+0000) Subject: retain/release checker: Add special handling of CGBitmapContextCreateWithData(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=882a51e497c7cf3c21530c51c5b6f44ff2560226;p=clang retain/release checker: Add special handling of CGBitmapContextCreateWithData(). Fixes: git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85864 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index c629ad1d96..120d422d37 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1036,6 +1036,17 @@ RetainSummary* RetainSummaryManager::getSummary(FunctionDecl* FD) { DoNothing); } break; + + case 29: + if (!memcmp(FName, "CGBitmapContextCreateWithData", 29)) { + // FIXES: + // Eventually this can be improved by recognizing that 'releaseInfo' + // passed to CGBitmapContextCreateWithData is released via + // a callback and doing full IPA to make sure this is done correctly. + ScratchArgs = AF.Add(ScratchArgs, 8, StopTracking); + S = getPersistentSummary(RetEffect::MakeNoRet(), DoNothing,DoNothing); + } + break; case 32: if (!memcmp(FName, "IOServiceAddMatchingNotification", 32)) { diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index e620037b2c..19ea5ed1c9 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -1097,6 +1097,32 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height, pixelBufferAttributes, pixelBufferOut) ; } +//===----------------------------------------------------------------------===// +// False leak associated with +// CGBitmapContextCreateWithData +//===----------------------------------------------------------------------===// +typedef uint32_t CGBitmapInfo; +typedef void (*CGBitmapContextReleaseDataCallback)(void *releaseInfo, void *data); + +CGContextRef CGBitmapContextCreateWithData(void *data, + size_t width, size_t height, size_t bitsPerComponent, + size_t bytesPerRow, CGColorSpaceRef space, CGBitmapInfo bitmapInfo, + CGBitmapContextReleaseDataCallback releaseCallback, void *releaseInfo); + +void rdar_7358899(void *data, + size_t width, size_t height, size_t bitsPerComponent, + size_t bytesPerRow, CGColorSpaceRef space, CGBitmapInfo bitmapInfo, + CGBitmapContextReleaseDataCallback releaseCallback) { + + // For the allocated object, it doesn't really matter what type it is + // for the purpose of this test. All we want to show is that + // this is freed later by the callback. + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning + + CGBitmapContextCreateWithData(data, width, height, bitsPerComponent, + bytesPerRow, space, bitmapInfo, releaseCallback, number); +} + //===----------------------------------------------------------------------===// // allow 'new', 'copy', 'alloc', 'init' prefix to // start before '_' when determining Cocoa fundamental rule