Skip to content

Commit 7ff6a8a

Browse files
committedJun 9, 2018
[analyzer] Clean up the program state map of DanglingInternalBufferChecker.
Symbols are cleaned up from the program state map when they go out of scope. Memory regions are cleaned up when the corresponding object is destroyed, and additionally in 'checkDeadSymbols' in case destructor modeling was incomplete. Differential Revision: https://reviews.llvm.org/D47416 llvm-svn: 334352
1 parent 5297506 commit 7ff6a8a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
 

‎clang/lib/StaticAnalyzer/Checkers/DanglingInternalBufferChecker.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ using namespace ento;
2626

2727
namespace {
2828

29-
class DanglingInternalBufferChecker : public Checker<check::PostCall> {
29+
class DanglingInternalBufferChecker : public Checker<check::DeadSymbols,
30+
check::PostCall> {
3031
CallDescription CStrFn;
3132

3233
public:
@@ -36,6 +37,9 @@ class DanglingInternalBufferChecker : public Checker<check::PostCall> {
3637
/// corresponding string object region in the ProgramState. Mark the symbol
3738
/// released if the string object is destroyed.
3839
void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
40+
41+
/// Clean up the ProgramState map.
42+
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
3943
};
4044

4145
} // end anonymous namespace
@@ -76,12 +80,29 @@ void DanglingInternalBufferChecker::checkPostCall(const CallEvent &Call,
7680
// FIXME: What if Origin is null?
7781
const Expr *Origin = Call.getOriginExpr();
7882
State = allocation_state::markReleased(State, *StrBufferPtr, Origin);
83+
State = State->remove<RawPtrMap>(TypedR);
7984
C.addTransition(State);
8085
return;
8186
}
8287
}
8388
}
8489

90+
void DanglingInternalBufferChecker::checkDeadSymbols(SymbolReaper &SymReaper,
91+
CheckerContext &C) const {
92+
ProgramStateRef State = C.getState();
93+
RawPtrMapTy RPM = State->get<RawPtrMap>();
94+
for (const auto Entry : RPM) {
95+
if (!SymReaper.isLive(Entry.second))
96+
State = State->remove<RawPtrMap>(Entry.first);
97+
if (!SymReaper.isLiveRegion(Entry.first)) {
98+
// Due to incomplete destructor support, some dead regions might still
99+
// remain in the program state map. Clean them up.
100+
State = State->remove<RawPtrMap>(Entry.first);
101+
}
102+
}
103+
C.addTransition(State);
104+
}
105+
85106
void ento::registerDanglingInternalBufferChecker(CheckerManager &Mgr) {
86107
registerNewDeleteChecker(Mgr);
87108
Mgr.registerChecker<DanglingInternalBufferChecker>();

0 commit comments

Comments
 (0)
Please sign in to comment.