From: Anton Yartsev Date: Fri, 5 Apr 2013 02:25:02 +0000 (+0000) Subject: [analyzer] Check allocation family more precise. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=418780f132a6d790b248ef91e1067c3c3dd31350;p=clang [analyzer] Check allocation family more precise. The statement passed to isTrackedFamily() might be a user defined function calling malloc; in this case we got AF_NONE family for this function. Now the allocation family is derived from Sym, that holds a family of a real allocator. This commit is also a movement towards getting rid of tracking memory allocating by unknown means. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178834 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 1e18792d89..4b0e7661d8 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1535,6 +1535,9 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N, !Filter.CNewDeleteChecker) return; + if (!isTrackedFamily(C, Sym)) + return; + assert(N); if (!BT_Leak) { BT_Leak.reset(new BugType("Memory leak", "Memory Error")); @@ -1560,13 +1563,10 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N, AllocationStmt = Exit->getCalleeContext()->getCallSite(); else if (Optional SP = P.getAs()) AllocationStmt = SP->getStmt(); - if (AllocationStmt) { + if (AllocationStmt) LocUsedForUniqueing = PathDiagnosticLocation::createBegin(AllocationStmt, C.getSourceManager(), AllocNode->getLocationContext()); - if (!isTrackedFamily(C, AllocationStmt)) - return; - } SmallString<200> buf; llvm::raw_svector_ostream os(buf);