|
@@ -334,10 +334,13 @@ private:
|
|
|
/// Tells if a given family/call/symbol is tracked by the current checker.
|
|
|
/// Sets CheckKind to the kind of the checker responsible for this
|
|
|
/// family/call/symbol.
|
|
|
- Optional<CheckKind> getCheckIfTracked(AllocationFamily Family) const;
|
|
|
+ Optional<CheckKind> getCheckIfTracked(AllocationFamily Family,
|
|
|
+ bool IsALeakCheck = false) const;
|
|
|
Optional<CheckKind> getCheckIfTracked(CheckerContext &C,
|
|
|
- const Stmt *AllocDeallocStmt) const;
|
|
|
- Optional<CheckKind> getCheckIfTracked(CheckerContext &C, SymbolRef Sym) const;
|
|
|
+ const Stmt *AllocDeallocStmt,
|
|
|
+ bool IsALeakCheck = false) const;
|
|
|
+ Optional<CheckKind> getCheckIfTracked(CheckerContext &C, SymbolRef Sym,
|
|
|
+ bool IsALeakCheck = false) const;
|
|
|
///@}
|
|
|
static bool SummarizeValue(raw_ostream &os, SVal V);
|
|
|
static bool SummarizeRegion(raw_ostream &os, const MemRegion *MR);
|
|
@@ -1342,7 +1345,8 @@ ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C,
|
|
|
}
|
|
|
|
|
|
Optional<MallocChecker::CheckKind>
|
|
|
-MallocChecker::getCheckIfTracked(AllocationFamily Family) const {
|
|
|
+MallocChecker::getCheckIfTracked(AllocationFamily Family,
|
|
|
+ bool IsALeakCheck) const {
|
|
|
switch (Family) {
|
|
|
case AF_Malloc:
|
|
|
case AF_Alloca:
|
|
@@ -1354,8 +1358,13 @@ MallocChecker::getCheckIfTracked(AllocationFamily Family) const {
|
|
|
}
|
|
|
case AF_CXXNew:
|
|
|
case AF_CXXNewArray: {
|
|
|
- if (ChecksEnabled[CK_NewDeleteChecker]) {
|
|
|
- return CK_NewDeleteChecker;
|
|
|
+ if (IsALeakCheck) {
|
|
|
+ if (ChecksEnabled[CK_NewDeleteLeaksChecker])
|
|
|
+ return CK_NewDeleteLeaksChecker;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (ChecksEnabled[CK_NewDeleteChecker])
|
|
|
+ return CK_NewDeleteChecker;
|
|
|
}
|
|
|
return Optional<MallocChecker::CheckKind>();
|
|
|
}
|
|
@@ -1368,16 +1377,18 @@ MallocChecker::getCheckIfTracked(AllocationFamily Family) const {
|
|
|
|
|
|
Optional<MallocChecker::CheckKind>
|
|
|
MallocChecker::getCheckIfTracked(CheckerContext &C,
|
|
|
- const Stmt *AllocDeallocStmt) const {
|
|
|
- return getCheckIfTracked(getAllocationFamily(C, AllocDeallocStmt));
|
|
|
+ const Stmt *AllocDeallocStmt,
|
|
|
+ bool IsALeakCheck) const {
|
|
|
+ return getCheckIfTracked(getAllocationFamily(C, AllocDeallocStmt),
|
|
|
+ IsALeakCheck);
|
|
|
}
|
|
|
|
|
|
Optional<MallocChecker::CheckKind>
|
|
|
-MallocChecker::getCheckIfTracked(CheckerContext &C, SymbolRef Sym) const {
|
|
|
-
|
|
|
+MallocChecker::getCheckIfTracked(CheckerContext &C, SymbolRef Sym,
|
|
|
+ bool IsALeakCheck) const {
|
|
|
const RefState *RS = C.getState()->get<RegionState>(Sym);
|
|
|
assert(RS);
|
|
|
- return getCheckIfTracked(RS->getAllocationFamily());
|
|
|
+ return getCheckIfTracked(RS->getAllocationFamily(), IsALeakCheck);
|
|
|
}
|
|
|
|
|
|
bool MallocChecker::SummarizeValue(raw_ostream &os, SVal V) {
|
|
@@ -1906,17 +1917,14 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N,
|
|
|
const RefState *RS = C.getState()->get<RegionState>(Sym);
|
|
|
assert(RS && "cannot leak an untracked symbol");
|
|
|
AllocationFamily Family = RS->getAllocationFamily();
|
|
|
- Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(Family);
|
|
|
- if (!CheckKind.hasValue())
|
|
|
+
|
|
|
+ if (Family == AF_Alloca)
|
|
|
return;
|
|
|
|
|
|
- // Special case for new and new[]; these are controlled by a separate checker
|
|
|
- // flag so that they can be selectively disabled.
|
|
|
- if (Family == AF_CXXNew || Family == AF_CXXNewArray)
|
|
|
- if (!ChecksEnabled[CK_NewDeleteLeaksChecker])
|
|
|
- return;
|
|
|
+ Optional<MallocChecker::CheckKind>
|
|
|
+ CheckKind = getCheckIfTracked(Family, true);
|
|
|
|
|
|
- if (RS->getAllocationFamily() == AF_Alloca)
|
|
|
+ if (!CheckKind.hasValue())
|
|
|
return;
|
|
|
|
|
|
assert(N);
|
|
@@ -2529,6 +2537,8 @@ void MallocChecker::printState(raw_ostream &Out, ProgramStateRef State,
|
|
|
const RefState *RefS = State->get<RegionState>(I.getKey());
|
|
|
AllocationFamily Family = RefS->getAllocationFamily();
|
|
|
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(Family);
|
|
|
+ if (!CheckKind.hasValue())
|
|
|
+ CheckKind = getCheckIfTracked(Family, true);
|
|
|
|
|
|
I.getKey()->dumpToStream(Out);
|
|
|
Out << " : ";
|