]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix a false positive reported on rare strange code, which happens to be...
authorAnna Zaks <ganna@apple.com>
Fri, 31 May 2013 22:39:13 +0000 (22:39 +0000)
committerAnna Zaks <ganna@apple.com>
Fri, 31 May 2013 22:39:13 +0000 (22:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183055 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/malloc.m

index 11abe9a41b79f2e2d33ab6df4e5dc9fd9b759444..bb2e2df2acfb95c367a01731b77f0e730ba1500a 100644 (file)
@@ -1890,6 +1890,12 @@ bool MallocChecker::doesNotFreeMemOrInteresting(const CallEvent *Call,
       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;
index 21d2dafa38b6ef9316483dd00c3aeb1c2d86f9fd..4c1e161db2d6f5dc20ef6c3118414d71432105bb 100644 (file)
@@ -35,3 +35,13 @@ void rdar10579586(char x);
 }
 @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