forked from OSchip/llvm-project
parent
63dc1f4694
commit
0bbf24d579
|
@ -24,7 +24,8 @@ using namespace clang;
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class RefState {
|
class RefState {
|
||||||
enum Kind { AllocateUnchecked, AllocateFailed, Released, Escaped, Relinquished } K;
|
enum Kind { AllocateUnchecked, AllocateFailed, Released, Escaped,
|
||||||
|
Relinquished } K;
|
||||||
const Stmt *S;
|
const Stmt *S;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -48,7 +49,9 @@ public:
|
||||||
}
|
}
|
||||||
static RefState getReleased(const Stmt *s) { return RefState(Released, s); }
|
static RefState getReleased(const Stmt *s) { return RefState(Released, s); }
|
||||||
static RefState getEscaped(const Stmt *s) { return RefState(Escaped, s); }
|
static RefState getEscaped(const Stmt *s) { return RefState(Escaped, s); }
|
||||||
static RefState getRelinquished(const Stmt *s) { return RefState(Relinquished, s); }
|
static RefState getRelinquished(const Stmt *s) {
|
||||||
|
return RefState(Relinquished, s);
|
||||||
|
}
|
||||||
|
|
||||||
void Profile(llvm::FoldingSetNodeID &ID) const {
|
void Profile(llvm::FoldingSetNodeID &ID) const {
|
||||||
ID.AddInteger(K);
|
ID.AddInteger(K);
|
||||||
|
@ -68,7 +71,8 @@ class MallocChecker : public CheckerVisitor<MallocChecker> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MallocChecker()
|
MallocChecker()
|
||||||
: BT_DoubleFree(0), BT_Leak(0), BT_UseFree(0), BT_UseRelinquished(0), BT_BadFree(0),
|
: BT_DoubleFree(0), BT_Leak(0), BT_UseFree(0), BT_UseRelinquished(0),
|
||||||
|
BT_BadFree(0),
|
||||||
II_malloc(0), II_free(0), II_realloc(0), II_calloc(0) {}
|
II_malloc(0), II_free(0), II_realloc(0), II_calloc(0) {}
|
||||||
static void *getTag();
|
static void *getTag();
|
||||||
bool EvalCallExpr(CheckerContext &C, const CallExpr *CE);
|
bool EvalCallExpr(CheckerContext &C, const CallExpr *CE);
|
||||||
|
@ -84,7 +88,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void MallocMem(CheckerContext &C, const CallExpr *CE);
|
void MallocMem(CheckerContext &C, const CallExpr *CE);
|
||||||
void MallocMemReturnsAttr(CheckerContext &C, const CallExpr *CE, const OwnershipAttr* Att);
|
void MallocMemReturnsAttr(CheckerContext &C, const CallExpr *CE,
|
||||||
|
const OwnershipAttr* Att);
|
||||||
const GRState *MallocMemAux(CheckerContext &C, const CallExpr *CE,
|
const GRState *MallocMemAux(CheckerContext &C, const CallExpr *CE,
|
||||||
const Expr *SizeEx, SVal Init,
|
const Expr *SizeEx, SVal Init,
|
||||||
const GRState *state) {
|
const GRState *state) {
|
||||||
|
@ -706,11 +711,14 @@ void MallocChecker::PreVisitBind(CheckerContext &C,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// If the state can't represent this binding, we still own it.
|
// If the state can't represent this binding, we still own it.
|
||||||
if (notNullState == (notNullState->bindLoc(cast<Loc>(location), UnknownVal())))
|
if (notNullState == (notNullState->bindLoc(cast<Loc>(location),
|
||||||
|
UnknownVal())))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// We no longer own this pointer.
|
// We no longer own this pointer.
|
||||||
notNullState = notNullState->set<RegionState>(Sym, RefState::getRelinquished(StoreE));
|
notNullState =
|
||||||
|
notNullState->set<RegionState>(Sym,
|
||||||
|
RefState::getRelinquished(StoreE));
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue