r183055 - [analyzer] Fix a false positive reported on rare strange code, which happens to be in JSONKit
Anna Zaks
ganna at apple.com
Fri May 31 15:39:14 PDT 2013
Author: zaks
Date: Fri May 31 17:39:13 2013
New Revision: 183055
URL: http://llvm.org/viewvc/llvm-project?rev=183055&view=rev
Log:
[analyzer] Fix a false positive reported on rare strange code, which happens to be in JSONKit
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/test/Analysis/malloc.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=183055&r1=183054&r2=183055&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Fri May 31 17:39:13 2013
@@ -1890,6 +1890,12 @@ bool MallocChecker::doesNotFreeMemOrInte
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;
Modified: cfe/trunk/test/Analysis/malloc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.m?rev=183055&r1=183054&r2=183055&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc.m (original)
+++ cfe/trunk/test/Analysis/malloc.m Fri May 31 17:39:13 2013
@@ -35,3 +35,13 @@ void rdar10579586(char x);
}
@end
+ at interface JKArray : NSObject {
+ id * objects;
+}
+ at end
+
+void _JKArrayCreate() {
+ JKArray *array = (JKArray *)malloc(12);
+ array = [array init];
+ free(array); // no-warning
+}
\ No newline at end of file
More information about the cfe-commits
mailing list