diff options
author | Anna Zaks <ganna@apple.com> | 2013-05-31 22:39:13 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2013-05-31 22:39:13 +0000 |
commit | 737926ba6cf7cd14e73fbbb79debabf1c3254ce2 (patch) | |
tree | c74ef21237777b190a3141604318da51b2764edd | |
parent | 1ec87e8bb0a36ce592567f3e7b9eeae8a215961b (diff) | |
download | bcm5719-llvm-737926ba6cf7cd14e73fbbb79debabf1c3254ce2.tar.gz bcm5719-llvm-737926ba6cf7cd14e73fbbb79debabf1c3254ce2.zip |
[analyzer] Fix a false positive reported on rare strange code, which happens to be in JSONKit
llvm-svn: 183055
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 6 | ||||
-rw-r--r-- | clang/test/Analysis/malloc.m | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 11abe9a41b7..bb2e2df2acf 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -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; diff --git a/clang/test/Analysis/malloc.m b/clang/test/Analysis/malloc.m index 21d2dafa38b..4c1e161db2d 100644 --- a/clang/test/Analysis/malloc.m +++ b/clang/test/Analysis/malloc.m @@ -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 |