]> granicus.if.org Git - clang/commitdiff
[analyzer] Malloc leak false positive: Allow xpc context to escape.
authorAnna Zaks <ganna@apple.com>
Wed, 20 Jun 2012 23:35:57 +0000 (23:35 +0000)
committerAnna Zaks <ganna@apple.com>
Wed, 20 Jun 2012 23:35:57 +0000 (23:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158875 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/malloc.c
test/Analysis/system-header-simulator.h

index 48fdec2d3f9fde3f62d5429569ca03bcf774ae42..3171c03eb024e02e6414d022f4d349d763c8d957 100644 (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
index c532d6813f4e0f9c6df51e24c4d176adb5fbb445..9596751a0d6bc01c1aa4d391e4e23f515f42b33b 100644 (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);
+}
+
index d2fb2e8684b2da902ca13162d7c7730c0a6717f9..5790fb9cff4a138d95db5553ddf96a07b4c5b192 100644 (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);