From ee1af2398086464cfa2b7306ac4d8359d61872ee Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Fri, 31 May 2013 22:39:13 +0000 Subject: [PATCH] [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 --- lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 6 ++++++ test/Analysis/malloc.m | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 11abe9a41b..bb2e2df2ac 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/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/test/Analysis/malloc.m b/test/Analysis/malloc.m index 21d2dafa38..4c1e161db2 100644 --- a/test/Analysis/malloc.m +++ b/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 -- 2.40.0