diff options
-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 |