[analyzer] Malloc leak false positive: Allow xpc context to escape.

llvm-svn: 158875
This commit is contained in:
Anna Zaks 2012-06-20 23:35:57 +00:00
parent 1501987951
commit 886dfb8cfa
3 changed files with 26 additions and 0 deletions

View File

@ -1298,6 +1298,12 @@ bool MallocChecker::doesNotFreeMemory(const CallOrObjCMessage *Call,
if (FName.equals("pthread_setspecific"))
return false;
// White list xpc connection context.
// TODO: Ensure that the deallocation actually happens, need to reason
// about "xpc_connection_set_finalizer_f".
if (FName.equals("xpc_connection_set_context"))
return false;
// White list the 'XXXNoCopy' ObjC functions.
if (FName.endswith("NoCopy")) {
// Look for the deallocator argument. We know that the memory ownership

View File

@ -974,3 +974,16 @@ void testCGContextLeak()
// object doesn't escape and it hasn't been freed in this function.
}
// Allow xpc context to escape. radar://11635258
// TODO: Would be great if we checked that the finalize_connection_context actually releases it.
static void finalize_connection_context(void *ctx) {
int *context = ctx;
free(context);
}
void foo (xpc_connection_t peer) {
int *ctx = calloc(1, sizeof(int));
xpc_connection_set_context(peer, ctx);
xpc_connection_set_finalizer_f(peer, finalize_connection_context);
xpc_connection_resume(peer);
}

View File

@ -53,3 +53,10 @@ CGContextRef CGBitmapContextCreate(void *data/*, size_t width, size_t height,
CGColorSpaceRef space,
CGBitmapInfo bitmapInfo*/);
void *CGBitmapContextGetData(CGContextRef context);
// Include xpc.
typedef struct _xpc_connection_s * xpc_connection_t;
typedef void (*xpc_finalizer_t)(void *value);
void xpc_connection_set_context(xpc_connection_t connection, void *context);
void xpc_connection_set_finalizer_f(xpc_connection_t connection, xpc_finalizer_t finalizer);
void xpc_connection_resume(xpc_connection_t connection);