diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-10-20 23:46:25 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-10-20 23:46:25 +0000 |
commit | 0ba497be27170c2a23c0217366f97eeecefa1ed8 (patch) | |
tree | 485c1da946d54c120feed16e7472e49ad8ee72d1 | |
parent | 48620bafe4ba879f96c2d17caefeb79f3fae2eea (diff) |
Use llvm::OwningPtr in CFGBuilder, fixing a leak on an error path.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84695 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/CFG.cpp | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 7b1d50cb3a..6945c2f376 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/Format.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/OwningPtr.h" using namespace clang; @@ -51,7 +52,7 @@ static SourceLocation GetEndLoc(Decl* D) { /// class VISIBILITY_HIDDEN CFGBuilder { ASTContext *Context; - CFG* cfg; + llvm::OwningPtr<CFG> cfg; CFGBlock* Block; CFGBlock* Succ; @@ -79,8 +80,6 @@ public: ContinueTargetBlock(NULL), BreakTargetBlock(NULL), SwitchTerminatedBlock(NULL), DefaultCaseBlock(NULL) {} - ~CFGBuilder() { delete cfg; } - // buildCFG - Used by external clients to construct the CFG. CFG* buildCFG(Stmt *Statement, ASTContext *C); @@ -195,7 +194,7 @@ static VariableArrayType* FindVA(Type* t) { /// NULL. CFG* CFGBuilder::buildCFG(Stmt* Statement, ASTContext* C) { Context = C; - assert(cfg); + assert(cfg.get()); if (!Statement) return NULL; @@ -210,7 +209,8 @@ CFG* CFGBuilder::buildCFG(Stmt* Statement, ASTContext* C) { // Visit the statements and create the CFG. CFGBlock* B = addStmt(Statement); - if (!B) B = Succ; + if (!B) + B = Succ; if (B) { // Finalize the last constructed block. This usually involves reversing the @@ -254,17 +254,12 @@ CFG* CFGBuilder::buildCFG(Stmt* Statement, ASTContext* C) { // Create an empty entry block that has no predecessors. cfg->setEntry(createBlock()); - if (badCFG) { - delete cfg; - cfg = NULL; + if (badCFG) return NULL; - } // NULL out cfg so that repeated calls to the builder will fail and that the // ownership of the constructed CFG is passed to the caller. - CFG* t = cfg; - cfg = NULL; - return t; + return cfg.take(); } /// createBlock - Used to lazily create blocks that are connected |