diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-02-15 02:47:45 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-02-15 02:47:45 +0000 |
commit | fe59b7472c06b36efb74fbb50bbdf464fa30c0d8 (patch) | |
tree | 508ca8b75856b1bd3243a6cf25b804df30edf5bb /lib | |
parent | dac54c124e302d6f028ea5723c425b7f66fc7c71 (diff) |
Fix memory leak in CFGBuilder resulting from tracking scope information using SmallVectors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125550 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/CFG.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index bc3699ba68..d46b7e7830 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -90,7 +90,7 @@ private: /// class LocalScope { public: - typedef llvm::SmallVector<VarDecl*, 4> AutomaticVarsTy; + typedef BumpVector<VarDecl*> AutomaticVarsTy; /// const_iterator - Iterates local scope backwards and jumps to previous /// scope on reaching the beginning of currently iterated scope. @@ -160,6 +160,8 @@ public: friend class const_iterator; private: + BumpVectorContext ctx; + /// Automatic variables in order of declaration. AutomaticVarsTy Vars; /// Iterator to variable in previous scope that was declared just before @@ -168,15 +170,14 @@ private: public: /// Constructs empty scope linked to previous scope in specified place. - LocalScope(const_iterator P) - : Vars() - , Prev(P) {} + LocalScope(BumpVectorContext &ctx, const_iterator P) + : ctx(ctx), Vars(ctx, 4), Prev(P) {} /// Begin of scope in direction of CFG building (backwards). const_iterator begin() const { return const_iterator(*this, Vars.size()); } void addVar(VarDecl* VD) { - Vars.push_back(VD); + Vars.push_back(VD, ctx); } }; @@ -630,8 +631,10 @@ void CFGBuilder::addImplicitDtorsForDestructor(const CXXDestructorDecl *DD) { /// way return valid LocalScope object. LocalScope* CFGBuilder::createOrReuseLocalScope(LocalScope* Scope) { if (!Scope) { - Scope = cfg->getAllocator().Allocate<LocalScope>(); - new (Scope) LocalScope(ScopePos); + llvm::BumpPtrAllocator &alloc = cfg->getAllocator(); + Scope = alloc.Allocate<LocalScope>(); + BumpVectorContext ctx(alloc); + new (Scope) LocalScope(ctx, ScopePos); } return Scope; } |