blob: dd919e3a9b0ab4ea0aebbae9b440f96c7e8964ba [file] [log] [blame]
Zhongxing Xu589c0f22009-11-12 08:38:56 +00001//=== MallocChecker.cpp - A malloc/free checker -------------------*- C++ -*--//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines malloc/free checker, which checks for potential memory
11// leaks, double free, and use-after-free problems.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000015#include "ClangSACheckers.h"
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000016#include "clang/StaticAnalyzer/Core/Checker.h"
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000017#include "clang/StaticAnalyzer/Core/CheckerManager.h"
18#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
Ted Kremenek9b663712011-02-10 01:03:03 +000019#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
Ted Kremenek18c66fd2011-08-15 22:09:50 +000020#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
21#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
Ted Kremenek9b663712011-02-10 01:03:03 +000022#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
Zhongxing Xu589c0f22009-11-12 08:38:56 +000023#include "llvm/ADT/ImmutableMap.h"
24using namespace clang;
Ted Kremenek9ef65372010-12-23 07:20:52 +000025using namespace ento;
Zhongxing Xu589c0f22009-11-12 08:38:56 +000026
27namespace {
28
Zhongxing Xu7fb14642009-12-11 00:55:44 +000029class RefState {
Ted Kremenekdde201b2010-08-06 21:12:55 +000030 enum Kind { AllocateUnchecked, AllocateFailed, Released, Escaped,
31 Relinquished } K;
Zhongxing Xu243fde92009-11-17 07:54:15 +000032 const Stmt *S;
33
Zhongxing Xu7fb14642009-12-11 00:55:44 +000034public:
Zhongxing Xu243fde92009-11-17 07:54:15 +000035 RefState(Kind k, const Stmt *s) : K(k), S(s) {}
36
Zhongxing Xub94b81a2009-12-31 06:13:07 +000037 bool isAllocated() const { return K == AllocateUnchecked; }
Chris Lattnerfae96222010-09-03 04:34:38 +000038 //bool isFailed() const { return K == AllocateFailed; }
Zhongxing Xu243fde92009-11-17 07:54:15 +000039 bool isReleased() const { return K == Released; }
Chris Lattnerfae96222010-09-03 04:34:38 +000040 //bool isEscaped() const { return K == Escaped; }
41 //bool isRelinquished() const { return K == Relinquished; }
Zhongxing Xu243fde92009-11-17 07:54:15 +000042
43 bool operator==(const RefState &X) const {
44 return K == X.K && S == X.S;
45 }
46
Zhongxing Xub94b81a2009-12-31 06:13:07 +000047 static RefState getAllocateUnchecked(const Stmt *s) {
48 return RefState(AllocateUnchecked, s);
49 }
50 static RefState getAllocateFailed() {
51 return RefState(AllocateFailed, 0);
52 }
Zhongxing Xu243fde92009-11-17 07:54:15 +000053 static RefState getReleased(const Stmt *s) { return RefState(Released, s); }
54 static RefState getEscaped(const Stmt *s) { return RefState(Escaped, s); }
Ted Kremenekdde201b2010-08-06 21:12:55 +000055 static RefState getRelinquished(const Stmt *s) {
56 return RefState(Relinquished, s);
57 }
Zhongxing Xu243fde92009-11-17 07:54:15 +000058
59 void Profile(llvm::FoldingSetNodeID &ID) const {
60 ID.AddInteger(K);
61 ID.AddPointer(S);
62 }
Zhongxing Xu589c0f22009-11-12 08:38:56 +000063};
64
Kovarththanan Rajaratnamba5fb5a2009-11-28 06:07:30 +000065class RegionState {};
Zhongxing Xu589c0f22009-11-12 08:38:56 +000066
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000067class MallocChecker : public Checker<eval::Call, check::DeadSymbols, check::EndPath, check::PreStmt<ReturnStmt>, check::Location,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000068 check::Bind, eval::Assume> {
69 mutable llvm::OwningPtr<BuiltinBug> BT_DoubleFree;
70 mutable llvm::OwningPtr<BuiltinBug> BT_Leak;
71 mutable llvm::OwningPtr<BuiltinBug> BT_UseFree;
72 mutable llvm::OwningPtr<BuiltinBug> BT_UseRelinquished;
73 mutable llvm::OwningPtr<BuiltinBug> BT_BadFree;
74 mutable IdentifierInfo *II_malloc, *II_free, *II_realloc, *II_calloc;
Zhongxing Xu589c0f22009-11-12 08:38:56 +000075
76public:
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000077 MallocChecker() : II_malloc(0), II_free(0), II_realloc(0), II_calloc(0) {}
78
79 bool evalCall(const CallExpr *CE, CheckerContext &C) const;
80 void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
Anna Zaksaf498a22011-10-25 19:56:48 +000081 void checkEndPath(CheckerContext &C) const;
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000082 void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
Ted Kremenek18c66fd2011-08-15 22:09:50 +000083 const ProgramState *evalAssume(const ProgramState *state, SVal Cond,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000084 bool Assumption) const;
Anna Zaks390909c2011-10-06 00:43:15 +000085 void checkLocation(SVal l, bool isLoad, const Stmt *S,
86 CheckerContext &C) const;
87 void checkBind(SVal location, SVal val, const Stmt*S,
88 CheckerContext &C) const;
Zhongxing Xub94b81a2009-12-31 06:13:07 +000089
Zhongxing Xu7b760962009-11-13 07:25:27 +000090private:
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000091 static void MallocMem(CheckerContext &C, const CallExpr *CE);
92 static void MallocMemReturnsAttr(CheckerContext &C, const CallExpr *CE,
93 const OwnershipAttr* Att);
Ted Kremenek18c66fd2011-08-15 22:09:50 +000094 static const ProgramState *MallocMemAux(CheckerContext &C, const CallExpr *CE,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000095 const Expr *SizeEx, SVal Init,
Ted Kremenek18c66fd2011-08-15 22:09:50 +000096 const ProgramState *state) {
Zhongxing Xua5ce9662010-06-01 03:01:33 +000097 return MallocMemAux(C, CE, state->getSVal(SizeEx), Init, state);
98 }
Ted Kremenek18c66fd2011-08-15 22:09:50 +000099 static const ProgramState *MallocMemAux(CheckerContext &C, const CallExpr *CE,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000100 SVal SizeEx, SVal Init,
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000101 const ProgramState *state);
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000102
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000103 void FreeMem(CheckerContext &C, const CallExpr *CE) const;
Jordy Rose2a479922010-08-12 08:54:03 +0000104 void FreeMemAttr(CheckerContext &C, const CallExpr *CE,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000105 const OwnershipAttr* Att) const;
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000106 const ProgramState *FreeMemAux(CheckerContext &C, const CallExpr *CE,
107 const ProgramState *state, unsigned Num, bool Hold) const;
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000108
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000109 void ReallocMem(CheckerContext &C, const CallExpr *CE) const;
110 static void CallocMem(CheckerContext &C, const CallExpr *CE);
Jordy Rose43859f62010-06-07 19:32:37 +0000111
Ted Kremenek9c378f72011-08-12 23:37:29 +0000112 static bool SummarizeValue(raw_ostream &os, SVal V);
113 static bool SummarizeRegion(raw_ostream &os, const MemRegion *MR);
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000114 void ReportBadFree(CheckerContext &C, SVal ArgVal, SourceRange range) const;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000115};
Kovarththanan Rajaratnamba5fb5a2009-11-28 06:07:30 +0000116} // end anonymous namespace
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000117
Zhongxing Xub94b81a2009-12-31 06:13:07 +0000118typedef llvm::ImmutableMap<SymbolRef, RefState> RegionStateTy;
119
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000120namespace clang {
Ted Kremenek9ef65372010-12-23 07:20:52 +0000121namespace ento {
Zhongxing Xu243fde92009-11-17 07:54:15 +0000122 template <>
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000123 struct ProgramStateTrait<RegionState>
124 : public ProgramStatePartialTrait<RegionStateTy> {
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000125 static void *GDMIndex() { static int x; return &x; }
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000126 };
127}
Argyrios Kyrtzidis5a4f98f2010-12-22 18:53:20 +0000128}
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000129
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000130bool MallocChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
Anna Zaksb805c8f2011-12-01 05:57:37 +0000131 const FunctionDecl *FD = C.getCalleeDecl(CE);
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000132 if (!FD)
Zhongxing Xua49c6b72009-12-11 03:09:01 +0000133 return false;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000134
135 ASTContext &Ctx = C.getASTContext();
136 if (!II_malloc)
137 II_malloc = &Ctx.Idents.get("malloc");
138 if (!II_free)
Zhongxing Xufc7ac8f2009-11-13 07:48:11 +0000139 II_free = &Ctx.Idents.get("free");
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000140 if (!II_realloc)
141 II_realloc = &Ctx.Idents.get("realloc");
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000142 if (!II_calloc)
143 II_calloc = &Ctx.Idents.get("calloc");
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000144
145 if (FD->getIdentifier() == II_malloc) {
146 MallocMem(C, CE);
Zhongxing Xua49c6b72009-12-11 03:09:01 +0000147 return true;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000148 }
149
150 if (FD->getIdentifier() == II_free) {
151 FreeMem(C, CE);
Zhongxing Xua49c6b72009-12-11 03:09:01 +0000152 return true;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000153 }
Zhongxing Xua49c6b72009-12-11 03:09:01 +0000154
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000155 if (FD->getIdentifier() == II_realloc) {
156 ReallocMem(C, CE);
157 return true;
158 }
159
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000160 if (FD->getIdentifier() == II_calloc) {
161 CallocMem(C, CE);
162 return true;
163 }
164
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000165 // Check all the attributes, if there are any.
166 // There can be multiple of these attributes.
167 bool rv = false;
168 if (FD->hasAttrs()) {
Sean Huntcf807c42010-08-18 23:23:40 +0000169 for (specific_attr_iterator<OwnershipAttr>
170 i = FD->specific_attr_begin<OwnershipAttr>(),
171 e = FD->specific_attr_end<OwnershipAttr>();
172 i != e; ++i) {
173 switch ((*i)->getOwnKind()) {
174 case OwnershipAttr::Returns: {
175 MallocMemReturnsAttr(C, CE, *i);
Jordy Rose2a479922010-08-12 08:54:03 +0000176 rv = true;
177 break;
Sean Huntcf807c42010-08-18 23:23:40 +0000178 }
179 case OwnershipAttr::Takes:
180 case OwnershipAttr::Holds: {
181 FreeMemAttr(C, CE, *i);
Jordy Rose2a479922010-08-12 08:54:03 +0000182 rv = true;
183 break;
Sean Huntcf807c42010-08-18 23:23:40 +0000184 }
Jordy Rose2a479922010-08-12 08:54:03 +0000185 default:
Jordy Rose2a479922010-08-12 08:54:03 +0000186 break;
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000187 }
188 }
189 }
190 return rv;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000191}
192
193void MallocChecker::MallocMem(CheckerContext &C, const CallExpr *CE) {
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000194 const ProgramState *state = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(),
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000195 C.getState());
Anna Zaks0bd6b112011-10-26 21:06:34 +0000196 C.addTransition(state);
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000197}
198
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000199void MallocChecker::MallocMemReturnsAttr(CheckerContext &C, const CallExpr *CE,
200 const OwnershipAttr* Att) {
Sean Huntcf807c42010-08-18 23:23:40 +0000201 if (Att->getModule() != "malloc")
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000202 return;
203
Sean Huntcf807c42010-08-18 23:23:40 +0000204 OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end();
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000205 if (I != E) {
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000206 const ProgramState *state =
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000207 MallocMemAux(C, CE, CE->getArg(*I), UndefinedVal(), C.getState());
Anna Zaks0bd6b112011-10-26 21:06:34 +0000208 C.addTransition(state);
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000209 return;
210 }
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000211 const ProgramState *state = MallocMemAux(C, CE, UnknownVal(), UndefinedVal(),
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000212 C.getState());
Anna Zaks0bd6b112011-10-26 21:06:34 +0000213 C.addTransition(state);
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000214}
215
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000216const ProgramState *MallocChecker::MallocMemAux(CheckerContext &C,
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000217 const CallExpr *CE,
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000218 SVal Size, SVal Init,
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000219 const ProgramState *state) {
Anna Zaks5d0ea6d2011-10-04 20:43:05 +0000220 unsigned Count = C.getCurrentBlockCount();
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000221 SValBuilder &svalBuilder = C.getSValBuilder();
Zhongxing Xua49c6b72009-12-11 03:09:01 +0000222
Jordy Rose32f26562010-07-04 00:00:41 +0000223 // Set the return value.
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000224 SVal retVal = svalBuilder.getConjuredSymbolVal(NULL, CE, CE->getType(), Count);
225 state = state->BindExpr(CE, retVal);
Zhongxing Xua49c6b72009-12-11 03:09:01 +0000226
Jordy Rose32f26562010-07-04 00:00:41 +0000227 // Fill the region with the initialization value.
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000228 state = state->bindDefault(retVal, Init);
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000229
Jordy Rose32f26562010-07-04 00:00:41 +0000230 // Set the region's extent equal to the Size parameter.
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000231 const SymbolicRegion *R = cast<SymbolicRegion>(retVal.getAsRegion());
232 DefinedOrUnknownSVal Extent = R->getExtent(svalBuilder);
Jordy Rose32f26562010-07-04 00:00:41 +0000233 DefinedOrUnknownSVal DefinedSize = cast<DefinedOrUnknownSVal>(Size);
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000234 DefinedOrUnknownSVal extentMatchesSize =
Ted Kremenek9c149532010-12-01 21:57:22 +0000235 svalBuilder.evalEQ(state, Extent, DefinedSize);
Jordy Rose32f26562010-07-04 00:00:41 +0000236
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000237 state = state->assume(extentMatchesSize, true);
238 assert(state);
239
240 SymbolRef Sym = retVal.getAsLocSymbol();
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000241 assert(Sym);
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000242
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000243 // Set the symbol's state to Allocated.
Zhongxing Xub94b81a2009-12-31 06:13:07 +0000244 return state->set<RegionState>(Sym, RefState::getAllocateUnchecked(CE));
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000245}
246
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000247void MallocChecker::FreeMem(CheckerContext &C, const CallExpr *CE) const {
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000248 const ProgramState *state = FreeMemAux(C, CE, C.getState(), 0, false);
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000249
250 if (state)
Anna Zaks0bd6b112011-10-26 21:06:34 +0000251 C.addTransition(state);
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000252}
253
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000254void MallocChecker::FreeMemAttr(CheckerContext &C, const CallExpr *CE,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000255 const OwnershipAttr* Att) const {
Sean Huntcf807c42010-08-18 23:23:40 +0000256 if (Att->getModule() != "malloc")
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000257 return;
258
Sean Huntcf807c42010-08-18 23:23:40 +0000259 for (OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end();
260 I != E; ++I) {
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000261 const ProgramState *state = FreeMemAux(C, CE, C.getState(), *I,
Sean Huntcf807c42010-08-18 23:23:40 +0000262 Att->getOwnKind() == OwnershipAttr::Holds);
263 if (state)
Anna Zaks0bd6b112011-10-26 21:06:34 +0000264 C.addTransition(state);
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000265 }
266}
267
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000268const ProgramState *MallocChecker::FreeMemAux(CheckerContext &C, const CallExpr *CE,
269 const ProgramState *state, unsigned Num,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000270 bool Hold) const {
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000271 const Expr *ArgExpr = CE->getArg(Num);
Jordy Rose43859f62010-06-07 19:32:37 +0000272 SVal ArgVal = state->getSVal(ArgExpr);
Zhongxing Xu181cc3d2010-02-14 06:49:48 +0000273
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000274 DefinedOrUnknownSVal location = cast<DefinedOrUnknownSVal>(ArgVal);
275
276 // Check for null dereferences.
277 if (!isa<Loc>(location))
Zhongxing Xu181cc3d2010-02-14 06:49:48 +0000278 return state;
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000279
280 // FIXME: Technically using 'Assume' here can result in a path
281 // bifurcation. In such cases we need to return two states, not just one.
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000282 const ProgramState *notNullState, *nullState;
Ted Kremenek28f47b92010-12-01 22:16:56 +0000283 llvm::tie(notNullState, nullState) = state->assume(location);
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000284
285 // The explicit NULL case, no operation is performed.
286 if (nullState && !notNullState)
287 return nullState;
288
289 assert(notNullState);
290
Jordy Rose43859f62010-06-07 19:32:37 +0000291 // Unknown values could easily be okay
292 // Undefined values are handled elsewhere
293 if (ArgVal.isUnknownOrUndef())
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000294 return notNullState;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000295
Jordy Rose43859f62010-06-07 19:32:37 +0000296 const MemRegion *R = ArgVal.getAsRegion();
297
298 // Nonlocs can't be freed, of course.
299 // Non-region locations (labels and fixed addresses) also shouldn't be freed.
300 if (!R) {
301 ReportBadFree(C, ArgVal, ArgExpr->getSourceRange());
302 return NULL;
303 }
304
305 R = R->StripCasts();
306
307 // Blocks might show up as heap data, but should not be free()d
308 if (isa<BlockDataRegion>(R)) {
309 ReportBadFree(C, ArgVal, ArgExpr->getSourceRange());
310 return NULL;
311 }
312
313 const MemSpaceRegion *MS = R->getMemorySpace();
314
315 // Parameters, locals, statics, and globals shouldn't be freed.
316 if (!(isa<UnknownSpaceRegion>(MS) || isa<HeapSpaceRegion>(MS))) {
317 // FIXME: at the time this code was written, malloc() regions were
318 // represented by conjured symbols, which are all in UnknownSpaceRegion.
319 // This means that there isn't actually anything from HeapSpaceRegion
320 // that should be freed, even though we allow it here.
321 // Of course, free() can work on memory allocated outside the current
322 // function, so UnknownSpaceRegion is always a possibility.
323 // False negatives are better than false positives.
324
325 ReportBadFree(C, ArgVal, ArgExpr->getSourceRange());
326 return NULL;
327 }
328
329 const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R);
330 // Various cases could lead to non-symbol values here.
331 // For now, ignore them.
332 if (!SR)
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000333 return notNullState;
Jordy Rose43859f62010-06-07 19:32:37 +0000334
335 SymbolRef Sym = SR->getSymbol();
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000336 const RefState *RS = state->get<RegionState>(Sym);
Zhongxing Xu7e3cda92010-01-18 03:27:34 +0000337
338 // If the symbol has not been tracked, return. This is possible when free() is
339 // called on a pointer that does not get its pointee directly from malloc().
340 // Full support of this requires inter-procedural analysis.
341 if (!RS)
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000342 return notNullState;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000343
344 // Check double free.
Zhongxing Xu243fde92009-11-17 07:54:15 +0000345 if (RS->isReleased()) {
Ted Kremenekd048c6e2010-12-20 21:19:09 +0000346 if (ExplodedNode *N = C.generateSink()) {
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000347 if (!BT_DoubleFree)
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000348 BT_DoubleFree.reset(
349 new BuiltinBug("Double free",
350 "Try to free a memory block that has been released"));
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000351 // FIXME: should find where it's freed last time.
352 BugReport *R = new BugReport(*BT_DoubleFree,
Benjamin Kramerd02e2322009-11-14 12:08:24 +0000353 BT_DoubleFree->getDescription(), N);
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000354 C.EmitReport(R);
355 }
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000356 return NULL;
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000357 }
358
359 // Normal free.
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000360 if (Hold)
361 return notNullState->set<RegionState>(Sym, RefState::getRelinquished(CE));
362 return notNullState->set<RegionState>(Sym, RefState::getReleased(CE));
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000363}
364
Ted Kremenek9c378f72011-08-12 23:37:29 +0000365bool MallocChecker::SummarizeValue(raw_ostream &os, SVal V) {
Jordy Rose43859f62010-06-07 19:32:37 +0000366 if (nonloc::ConcreteInt *IntVal = dyn_cast<nonloc::ConcreteInt>(&V))
367 os << "an integer (" << IntVal->getValue() << ")";
368 else if (loc::ConcreteInt *ConstAddr = dyn_cast<loc::ConcreteInt>(&V))
369 os << "a constant address (" << ConstAddr->getValue() << ")";
370 else if (loc::GotoLabel *Label = dyn_cast<loc::GotoLabel>(&V))
Chris Lattner68106302011-02-17 05:38:27 +0000371 os << "the address of the label '" << Label->getLabel()->getName() << "'";
Jordy Rose43859f62010-06-07 19:32:37 +0000372 else
373 return false;
374
375 return true;
376}
377
Ted Kremenek9c378f72011-08-12 23:37:29 +0000378bool MallocChecker::SummarizeRegion(raw_ostream &os,
Jordy Rose43859f62010-06-07 19:32:37 +0000379 const MemRegion *MR) {
380 switch (MR->getKind()) {
381 case MemRegion::FunctionTextRegionKind: {
382 const FunctionDecl *FD = cast<FunctionTextRegion>(MR)->getDecl();
383 if (FD)
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000384 os << "the address of the function '" << *FD << '\'';
Jordy Rose43859f62010-06-07 19:32:37 +0000385 else
386 os << "the address of a function";
387 return true;
388 }
389 case MemRegion::BlockTextRegionKind:
390 os << "block text";
391 return true;
392 case MemRegion::BlockDataRegionKind:
393 // FIXME: where the block came from?
394 os << "a block";
395 return true;
396 default: {
397 const MemSpaceRegion *MS = MR->getMemorySpace();
398
399 switch (MS->getKind()) {
400 case MemRegion::StackLocalsSpaceRegionKind: {
401 const VarRegion *VR = dyn_cast<VarRegion>(MR);
402 const VarDecl *VD;
403 if (VR)
404 VD = VR->getDecl();
405 else
406 VD = NULL;
407
408 if (VD)
409 os << "the address of the local variable '" << VD->getName() << "'";
410 else
411 os << "the address of a local stack variable";
412 return true;
413 }
414 case MemRegion::StackArgumentsSpaceRegionKind: {
415 const VarRegion *VR = dyn_cast<VarRegion>(MR);
416 const VarDecl *VD;
417 if (VR)
418 VD = VR->getDecl();
419 else
420 VD = NULL;
421
422 if (VD)
423 os << "the address of the parameter '" << VD->getName() << "'";
424 else
425 os << "the address of a parameter";
426 return true;
427 }
Ted Kremenekdcee3ce2010-07-01 20:16:50 +0000428 case MemRegion::NonStaticGlobalSpaceRegionKind:
429 case MemRegion::StaticGlobalSpaceRegionKind: {
Jordy Rose43859f62010-06-07 19:32:37 +0000430 const VarRegion *VR = dyn_cast<VarRegion>(MR);
431 const VarDecl *VD;
432 if (VR)
433 VD = VR->getDecl();
434 else
435 VD = NULL;
436
437 if (VD) {
438 if (VD->isStaticLocal())
439 os << "the address of the static variable '" << VD->getName() << "'";
440 else
441 os << "the address of the global variable '" << VD->getName() << "'";
442 } else
443 os << "the address of a global variable";
444 return true;
445 }
446 default:
447 return false;
448 }
449 }
450 }
451}
452
453void MallocChecker::ReportBadFree(CheckerContext &C, SVal ArgVal,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000454 SourceRange range) const {
Ted Kremenekd048c6e2010-12-20 21:19:09 +0000455 if (ExplodedNode *N = C.generateSink()) {
Jordy Rose43859f62010-06-07 19:32:37 +0000456 if (!BT_BadFree)
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000457 BT_BadFree.reset(new BuiltinBug("Bad free"));
Jordy Rose43859f62010-06-07 19:32:37 +0000458
459 llvm::SmallString<100> buf;
460 llvm::raw_svector_ostream os(buf);
461
462 const MemRegion *MR = ArgVal.getAsRegion();
463 if (MR) {
464 while (const ElementRegion *ER = dyn_cast<ElementRegion>(MR))
465 MR = ER->getSuperRegion();
466
467 // Special case for alloca()
468 if (isa<AllocaRegion>(MR))
469 os << "Argument to free() was allocated by alloca(), not malloc()";
470 else {
471 os << "Argument to free() is ";
472 if (SummarizeRegion(os, MR))
473 os << ", which is not memory allocated by malloc()";
474 else
475 os << "not memory allocated by malloc()";
476 }
477 } else {
478 os << "Argument to free() is ";
479 if (SummarizeValue(os, ArgVal))
480 os << ", which is not memory allocated by malloc()";
481 else
482 os << "not memory allocated by malloc()";
483 }
484
Anna Zakse172e8b2011-08-17 23:00:25 +0000485 BugReport *R = new BugReport(*BT_BadFree, os.str(), N);
Jordy Rose43859f62010-06-07 19:32:37 +0000486 R->addRange(range);
487 C.EmitReport(R);
488 }
489}
490
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000491void MallocChecker::ReallocMem(CheckerContext &C, const CallExpr *CE) const {
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000492 const ProgramState *state = C.getState();
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000493 const Expr *arg0Expr = CE->getArg(0);
494 DefinedOrUnknownSVal arg0Val
495 = cast<DefinedOrUnknownSVal>(state->getSVal(arg0Expr));
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000496
Ted Kremenek846eabd2010-12-01 21:28:31 +0000497 SValBuilder &svalBuilder = C.getSValBuilder();
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000498
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000499 DefinedOrUnknownSVal PtrEQ =
500 svalBuilder.evalEQ(state, arg0Val, svalBuilder.makeNull());
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000501
Lenny Maiorani4d8d8032011-04-27 14:49:29 +0000502 // Get the size argument. If there is no size arg then give up.
503 const Expr *Arg1 = CE->getArg(1);
504 if (!Arg1)
505 return;
506
507 // Get the value of the size argument.
508 DefinedOrUnknownSVal Arg1Val =
509 cast<DefinedOrUnknownSVal>(state->getSVal(Arg1));
510
511 // Compare the size argument to 0.
512 DefinedOrUnknownSVal SizeZero =
513 svalBuilder.evalEQ(state, Arg1Val,
514 svalBuilder.makeIntValWithPtrWidth(0, false));
515
516 // If the ptr is NULL and the size is not 0, the call is equivalent to
517 // malloc(size).
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000518 const ProgramState *stateEqual = state->assume(PtrEQ, true);
Lenny Maiorani4d8d8032011-04-27 14:49:29 +0000519 if (stateEqual && state->assume(SizeZero, false)) {
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000520 // Hack: set the NULL symbolic region to released to suppress false warning.
521 // In the future we should add more states for allocated regions, e.g.,
522 // CheckedNull, CheckedNonNull.
523
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000524 SymbolRef Sym = arg0Val.getAsLocSymbol();
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000525 if (Sym)
526 stateEqual = stateEqual->set<RegionState>(Sym, RefState::getReleased(CE));
527
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000528 const ProgramState *stateMalloc = MallocMemAux(C, CE, CE->getArg(1),
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000529 UndefinedVal(), stateEqual);
Anna Zaks0bd6b112011-10-26 21:06:34 +0000530 C.addTransition(stateMalloc);
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000531 }
532
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000533 if (const ProgramState *stateNotEqual = state->assume(PtrEQ, false)) {
Lenny Maiorani4d8d8032011-04-27 14:49:29 +0000534 // If the size is 0, free the memory.
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000535 if (const ProgramState *stateSizeZero = stateNotEqual->assume(SizeZero, true))
536 if (const ProgramState *stateFree =
Lenny Maiorani4d8d8032011-04-27 14:49:29 +0000537 FreeMemAux(C, CE, stateSizeZero, 0, false)) {
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000538
Zhongxing Xud56763f2011-09-01 04:53:59 +0000539 // Bind the return value to NULL because it is now free.
Anna Zaks0bd6b112011-10-26 21:06:34 +0000540 C.addTransition(stateFree->BindExpr(CE, svalBuilder.makeNull(), true));
Lenny Maiorani4d8d8032011-04-27 14:49:29 +0000541 }
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000542 if (const ProgramState *stateSizeNotZero = stateNotEqual->assume(SizeZero,false))
543 if (const ProgramState *stateFree = FreeMemAux(C, CE, stateSizeNotZero,
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000544 0, false)) {
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000545 // FIXME: We should copy the content of the original buffer.
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000546 const ProgramState *stateRealloc = MallocMemAux(C, CE, CE->getArg(1),
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000547 UnknownVal(), stateFree);
Anna Zaks0bd6b112011-10-26 21:06:34 +0000548 C.addTransition(stateRealloc);
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000549 }
Zhongxing Xud9c84c82009-12-12 12:29:38 +0000550 }
Zhongxing Xu589c0f22009-11-12 08:38:56 +0000551}
Zhongxing Xu7b760962009-11-13 07:25:27 +0000552
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000553void MallocChecker::CallocMem(CheckerContext &C, const CallExpr *CE) {
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000554 const ProgramState *state = C.getState();
Ted Kremenek846eabd2010-12-01 21:28:31 +0000555 SValBuilder &svalBuilder = C.getSValBuilder();
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000556
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000557 SVal count = state->getSVal(CE->getArg(0));
558 SVal elementSize = state->getSVal(CE->getArg(1));
559 SVal TotalSize = svalBuilder.evalBinOp(state, BO_Mul, count, elementSize,
560 svalBuilder.getContext().getSizeType());
561 SVal zeroVal = svalBuilder.makeZeroVal(svalBuilder.getContext().CharTy);
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000562
Anna Zaks0bd6b112011-10-26 21:06:34 +0000563 C.addTransition(MallocMemAux(C, CE, TotalSize, zeroVal, state));
Zhongxing Xua5ce9662010-06-01 03:01:33 +0000564}
565
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000566void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper,
567 CheckerContext &C) const
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000568{
Zhongxing Xu173ff562010-08-15 08:19:57 +0000569 if (!SymReaper.hasDeadSymbols())
570 return;
Zhongxing Xufc7ac8f2009-11-13 07:48:11 +0000571
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000572 const ProgramState *state = C.getState();
Zhongxing Xu173ff562010-08-15 08:19:57 +0000573 RegionStateTy RS = state->get<RegionState>();
Jordy Rose90760142010-08-18 04:33:47 +0000574 RegionStateTy::Factory &F = state->get_context<RegionState>();
Zhongxing Xu173ff562010-08-15 08:19:57 +0000575
Ted Kremenek217470e2011-07-28 23:07:51 +0000576 bool generateReport = false;
577
Zhongxing Xu173ff562010-08-15 08:19:57 +0000578 for (RegionStateTy::iterator I = RS.begin(), E = RS.end(); I != E; ++I) {
579 if (SymReaper.isDead(I->first)) {
Ted Kremenek217470e2011-07-28 23:07:51 +0000580 if (I->second.isAllocated())
581 generateReport = true;
Jordy Rose90760142010-08-18 04:33:47 +0000582
583 // Remove the dead symbol from the map.
Ted Kremenek3baf6722010-11-24 00:54:37 +0000584 RS = F.remove(RS, I->first);
Ted Kremenek217470e2011-07-28 23:07:51 +0000585
Zhongxing Xufc7ac8f2009-11-13 07:48:11 +0000586 }
587 }
Ted Kremenek217470e2011-07-28 23:07:51 +0000588
Anna Zaks0bd6b112011-10-26 21:06:34 +0000589 ExplodedNode *N = C.addTransition(state->set<RegionState>(RS));
Ted Kremenek217470e2011-07-28 23:07:51 +0000590
591 // FIXME: This does not handle when we have multiple leaks at a single
592 // place.
593 if (N && generateReport) {
594 if (!BT_Leak)
595 BT_Leak.reset(new BuiltinBug("Memory leak",
596 "Allocated memory never released. Potential memory leak."));
597 // FIXME: where it is allocated.
598 BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
599 C.EmitReport(R);
600 }
Zhongxing Xu7b760962009-11-13 07:25:27 +0000601}
Zhongxing Xu243fde92009-11-17 07:54:15 +0000602
Anna Zaksaf498a22011-10-25 19:56:48 +0000603void MallocChecker::checkEndPath(CheckerContext &Ctx) const {
604 const ProgramState *state = Ctx.getState();
Jordy Rose09cef092010-08-18 04:26:59 +0000605 RegionStateTy M = state->get<RegionState>();
Zhongxing Xu243fde92009-11-17 07:54:15 +0000606
Jordy Rose09cef092010-08-18 04:26:59 +0000607 for (RegionStateTy::iterator I = M.begin(), E = M.end(); I != E; ++I) {
Zhongxing Xu243fde92009-11-17 07:54:15 +0000608 RefState RS = I->second;
609 if (RS.isAllocated()) {
Anna Zaks0bd6b112011-10-26 21:06:34 +0000610 ExplodedNode *N = Ctx.addTransition(state);
Zhongxing Xu243fde92009-11-17 07:54:15 +0000611 if (N) {
612 if (!BT_Leak)
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000613 BT_Leak.reset(new BuiltinBug("Memory leak",
614 "Allocated memory never released. Potential memory leak."));
Zhongxing Xu243fde92009-11-17 07:54:15 +0000615 BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
Anna Zaksaf498a22011-10-25 19:56:48 +0000616 Ctx.EmitReport(R);
Zhongxing Xu243fde92009-11-17 07:54:15 +0000617 }
618 }
619 }
620}
Zhongxing Xu4985e3e2009-11-17 08:58:18 +0000621
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000622void MallocChecker::checkPreStmt(const ReturnStmt *S, CheckerContext &C) const {
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000623 const Expr *retExpr = S->getRetValue();
624 if (!retExpr)
Zhongxing Xu4985e3e2009-11-17 08:58:18 +0000625 return;
626
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000627 const ProgramState *state = C.getState();
Zhongxing Xu4985e3e2009-11-17 08:58:18 +0000628
Ted Kremenekc8413fd2010-12-02 07:49:45 +0000629 SymbolRef Sym = state->getSVal(retExpr).getAsSymbol();
Zhongxing Xu4985e3e2009-11-17 08:58:18 +0000630 if (!Sym)
631 return;
632
633 const RefState *RS = state->get<RegionState>(Sym);
634 if (!RS)
635 return;
636
637 // FIXME: check other cases.
638 if (RS->isAllocated())
639 state = state->set<RegionState>(Sym, RefState::getEscaped(S));
640
Anna Zaks0bd6b112011-10-26 21:06:34 +0000641 C.addTransition(state);
Zhongxing Xu4985e3e2009-11-17 08:58:18 +0000642}
Zhongxing Xub94b81a2009-12-31 06:13:07 +0000643
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000644const ProgramState *MallocChecker::evalAssume(const ProgramState *state, SVal Cond,
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000645 bool Assumption) const {
Zhongxing Xub94b81a2009-12-31 06:13:07 +0000646 // If a symblic region is assumed to NULL, set its state to AllocateFailed.
647 // FIXME: should also check symbols assumed to non-null.
648
649 RegionStateTy RS = state->get<RegionState>();
650
651 for (RegionStateTy::iterator I = RS.begin(), E = RS.end(); I != E; ++I) {
Zhongxing Xu2bfa3012011-04-02 03:20:45 +0000652 // If the symbol is assumed to NULL, this will return an APSInt*.
Zhongxing Xub94b81a2009-12-31 06:13:07 +0000653 if (state->getSymVal(I.getKey()))
654 state = state->set<RegionState>(I.getKey(),RefState::getAllocateFailed());
655 }
656
657 return state;
658}
Zhongxing Xuc8023782010-03-10 04:58:55 +0000659
660// Check if the location is a freed symbolic region.
Anna Zaks390909c2011-10-06 00:43:15 +0000661void MallocChecker::checkLocation(SVal l, bool isLoad, const Stmt *S,
662 CheckerContext &C) const {
Zhongxing Xuc8023782010-03-10 04:58:55 +0000663 SymbolRef Sym = l.getLocSymbolInBase();
664 if (Sym) {
665 const RefState *RS = C.getState()->get<RegionState>(Sym);
Ted Kremenekcea68652010-08-06 21:12:49 +0000666 if (RS && RS->isReleased()) {
Anna Zaks0bd6b112011-10-26 21:06:34 +0000667 if (ExplodedNode *N = C.addTransition()) {
Zhongxing Xuc8023782010-03-10 04:58:55 +0000668 if (!BT_UseFree)
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000669 BT_UseFree.reset(new BuiltinBug("Use dynamically allocated memory "
670 "after it is freed."));
Zhongxing Xuc8023782010-03-10 04:58:55 +0000671
672 BugReport *R = new BugReport(*BT_UseFree, BT_UseFree->getDescription(),
673 N);
674 C.EmitReport(R);
675 }
Ted Kremenekcea68652010-08-06 21:12:49 +0000676 }
Zhongxing Xuc8023782010-03-10 04:58:55 +0000677 }
678}
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000679
Anna Zaks390909c2011-10-06 00:43:15 +0000680void MallocChecker::checkBind(SVal location, SVal val,
681 const Stmt *BindS, CheckerContext &C) const {
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000682 // The PreVisitBind implements the same algorithm as already used by the
683 // Objective C ownership checker: if the pointer escaped from this scope by
684 // assignment, let it go. However, assigning to fields of a stack-storage
685 // structure does not transfer ownership.
686
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000687 const ProgramState *state = C.getState();
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000688 DefinedOrUnknownSVal l = cast<DefinedOrUnknownSVal>(location);
689
690 // Check for null dereferences.
691 if (!isa<Loc>(l))
692 return;
693
694 // Before checking if the state is null, check if 'val' has a RefState.
695 // Only then should we check for null and bifurcate the state.
696 SymbolRef Sym = val.getLocSymbolInBase();
697 if (Sym) {
698 if (const RefState *RS = state->get<RegionState>(Sym)) {
699 // If ptr is NULL, no operation is performed.
Ted Kremenek18c66fd2011-08-15 22:09:50 +0000700 const ProgramState *notNullState, *nullState;
Ted Kremenek28f47b92010-12-01 22:16:56 +0000701 llvm::tie(notNullState, nullState) = state->assume(l);
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000702
703 // Generate a transition for 'nullState' to record the assumption
704 // that the state was null.
705 if (nullState)
Anna Zaks0bd6b112011-10-26 21:06:34 +0000706 C.addTransition(nullState);
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000707
708 if (!notNullState)
709 return;
710
711 if (RS->isAllocated()) {
712 // Something we presently own is being assigned somewhere.
713 const MemRegion *AR = location.getAsRegion();
714 if (!AR)
715 return;
716 AR = AR->StripCasts()->getBaseRegion();
717 do {
718 // If it is on the stack, we still own it.
719 if (AR->hasStackNonParametersStorage())
720 break;
721
722 // If the state can't represent this binding, we still own it.
Ted Kremenekdde201b2010-08-06 21:12:55 +0000723 if (notNullState == (notNullState->bindLoc(cast<Loc>(location),
724 UnknownVal())))
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000725 break;
726
727 // We no longer own this pointer.
Ted Kremenekdde201b2010-08-06 21:12:55 +0000728 notNullState =
729 notNullState->set<RegionState>(Sym,
Anna Zaks390909c2011-10-06 00:43:15 +0000730 RefState::getRelinquished(BindS));
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000731 }
732 while (false);
733 }
Anna Zaks0bd6b112011-10-26 21:06:34 +0000734 C.addTransition(notNullState);
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000735 }
736 }
737}
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +0000738
739void ento::registerMallocChecker(CheckerManager &mgr) {
740 mgr.registerChecker<MallocChecker>();
741}