[analyzer] Fix a false positive reported on rare strange code, which happens to be in JSONKit
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183055 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 11abe9a..bb2e2df 100644
--- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1890,6 +1890,12 @@
return false;
}
+ // We should escape on call to 'init'. This is especially relevant to the
+ // receiver, as the corresponding symbol is usually not referenced after
+ // the call.
+ if (Msg->getMethodFamily() == OMF_init)
+ return false;
+
// Otherwise, assume that the method does not free memory.
// Most framework methods do not free memory.
return true;
diff --git a/test/Analysis/malloc.m b/test/Analysis/malloc.m
index 21d2daf..4c1e161 100644
--- a/test/Analysis/malloc.m
+++ b/test/Analysis/malloc.m
@@ -35,3 +35,13 @@
}
@end
+@interface JKArray : NSObject {
+ id * objects;
+}
+@end
+
+void _JKArrayCreate() {
+ JKArray *array = (JKArray *)malloc(12);
+ array = [array init];
+ free(array); // no-warning
+}
\ No newline at end of file