]> granicus.if.org Git - clang/commitdiff
fix leakage of var's initializers
authorNuno Lopes <nunoplopes@sapo.pt>
Wed, 17 Dec 2008 23:39:55 +0000 (23:39 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Wed, 17 Dec 2008 23:39:55 +0000 (23:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61171 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
lib/AST/Decl.cpp

index 57b967ec680185d2c47d7580048ea0552e6d0ab1..c3589cdfd73bacfdbdb7fb48fa6cad81042f71f4 100644 (file)
@@ -344,7 +344,10 @@ public:
                          SourceLocation L, IdentifierInfo *Id,
                          QualType T, StorageClass S, ScopedDecl *PrevDecl,
                          SourceLocation TypeSpecStartLoc = SourceLocation());
-  
+
+  virtual ~VarDecl();
+  virtual void Destroy(ASTContext& C);
+
   StorageClass getStorageClass() const { return (StorageClass)SClass; }
 
   SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
index dcefaa915b7b964891e33a7d6ef5bae5d4fc8dd4..be8cbe7344dc657652f4b8ae2ffe9f96029ea863 100644 (file)
@@ -14,6 +14,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Stmt.h"
+#include "clang/AST/Expr.h"
 #include "clang/Basic/IdentifierTable.h"
 
 using namespace clang;
@@ -48,15 +49,6 @@ ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
   return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T, PrevDecl);
 }
 
-VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
-                         SourceLocation L,
-                         IdentifierInfo *Id, QualType T,
-                         StorageClass S, ScopedDecl *PrevDecl,
-                         SourceLocation TypeSpecStartLoc) {
-  void *Mem = C.getAllocator().Allocate<VarDecl>();
-  return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl, TypeSpecStartLoc);
-}
-
 ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation L, IdentifierInfo *Id,
                                  QualType T, StorageClass S,
@@ -165,6 +157,28 @@ ScopedDecl::~ScopedDecl() {
     delete getMultipleDC();
 }
 
+//===----------------------------------------------------------------------===//
+// VarDecl Implementation
+//===----------------------------------------------------------------------===//
+
+VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
+                         SourceLocation L,
+                         IdentifierInfo *Id, QualType T,
+                         StorageClass S, ScopedDecl *PrevDecl,
+                         SourceLocation TypeSpecStartLoc) {
+  void *Mem = C.getAllocator().Allocate<VarDecl>();
+  return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl, TypeSpecStartLoc);
+}
+
+void VarDecl::Destroy(ASTContext& C) {
+  this->~VarDecl();
+  C.getAllocator().Deallocate((void *)this);
+}
+
+VarDecl::~VarDecl() {
+  delete getInit();
+}
+
 //===----------------------------------------------------------------------===//
 // FunctionDecl Implementation
 //===----------------------------------------------------------------------===//