summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-06-20 23:35:57 +0000
committerAnna Zaks <ganna@apple.com>2012-06-20 23:35:57 +0000
commit886dfb8cfa01d963803f872d9d756fcc11f650fb (patch)
tree6afe7b4edabe8884d173ca45eb34dfad1091fa9e
parent15019879511d98b8c489c857eba110b85f7b1a8c (diff)
downloadbcm5719-llvm-886dfb8cfa01d963803f872d9d756fcc11f650fb.tar.gz
bcm5719-llvm-886dfb8cfa01d963803f872d9d756fcc11f650fb.zip
[analyzer] Malloc leak false positive: Allow xpc context to escape.
llvm-svn: 158875
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp6
-rw-r--r--clang/test/Analysis/malloc.c13
-rw-r--r--clang/test/Analysis/system-header-simulator.h7
3 files changed, 26 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 48fdec2d3f9..3171c03eb02 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -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
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index c532d6813f4..9596751a0d6 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -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);
+}
+
diff --git a/clang/test/Analysis/system-header-simulator.h b/clang/test/Analysis/system-header-simulator.h
index d2fb2e8684b..5790fb9cff4 100644
--- a/clang/test/Analysis/system-header-simulator.h
+++ b/clang/test/Analysis/system-header-simulator.h
@@ -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);
OpenPOWER on IntegriCloud