aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/TranslationUnit.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-05-20 00:43:19 +0000
committerTed Kremenek <kremenek@apple.com>2008-05-20 00:43:19 +0000
commit27f8a28bee33bb0e857cfe1a61c281bbc234b338 (patch)
tree5e0cc27d9b0948a8cd6bc99306411a03d35d49fe /lib/AST/TranslationUnit.cpp
parent017cbdfd5417d4d31ae6406421276f90269f75e2 (diff)
Try to plug some memory leaks...
1) Sema::ParseAST now constructs a TranslationUnit object to own the top-level Decls, which releases the top-level Decls upon exiting ParseAST. 2) Bug fix: TranslationUnit::~TranslationUnit handles the case where a Decl is added more than once as a top-level Decl. 3) Decl::Destroy is now a virtual method, obviating the need for a special dispatch based on DeclKind. 3) FunctionDecl::Destroy now releases its Body using its Destroy method. 4) Added Stmt::Destroy and Stmt::DestroyChildren, which recursively delete the child ASTs of a Stmt and call their dstors. We may need to special case dstor/Destroy methods for particular Stmt subclasses that own other dynamically allocated objects besides AST nodes. 5) REGRESSION: We temporarily are not deallocating attributes; a FIXME is provided. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/TranslationUnit.cpp')
-rw-r--r--lib/AST/TranslationUnit.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp
index 5c043efeb3..9d7758648d 100644
--- a/lib/AST/TranslationUnit.cpp
+++ b/lib/AST/TranslationUnit.cpp
@@ -20,9 +20,9 @@
#include "llvm/Bitcode/Deserialize.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/System/Path.h"
-#include "llvm/ADT/OwningPtr.h"
-#include <stdio.h>
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/DenseSet.h"
using namespace clang;
@@ -31,8 +31,15 @@ enum { BasicMetadataBlock = 1,
DeclsBlock = 3 };
TranslationUnit::~TranslationUnit() {
- for (iterator I=begin(), E=end(); I!=E; ++I)
+
+ llvm::DenseSet<Decl*> Killed;
+
+ for (iterator I=begin(), E=end(); I!=E; ++I) {
+ if (Killed.count(*I)) continue;
+
+ Killed.insert(*I);
(*I)->Destroy(*Context);
+ }
if (OwnsMetaData && Context) {
// The ASTContext object has the sole references to the IdentifierTable