]> granicus.if.org Git - clang/commitdiff
Use the allocator associated with ASTContext to allocate the args
authorTed Kremenek <kremenek@apple.com>
Thu, 11 Feb 2010 07:31:47 +0000 (07:31 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 11 Feb 2010 07:31:47 +0000 (07:31 +0000)
array associated with NonNullAttr.  This fixes yet another leak when
ASTContext uses a BumpPtrAllocator.

Fixes: <rdar://problem/7637150>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95863 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
lib/AST/AttrImpl.cpp
lib/Frontend/PCHReaderDecl.cpp
lib/Sema/SemaDeclAttr.cpp

index ab8e2c649d5ca0a81772ed37ba03a29cd355c2e6..37225907c6def76d34e0988eeae902959600921c 100644 (file)
@@ -361,19 +361,9 @@ class NonNullAttr : public Attr {
   unsigned* ArgNums;
   unsigned Size;
 public:
-  NonNullAttr(unsigned* arg_nums = 0, unsigned size = 0) : Attr(NonNull),
-    ArgNums(0), Size(0) {
-
-    if (size == 0) return;
-    assert(arg_nums);
-    ArgNums = new unsigned[size];
-    Size = size;
-    memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size);
-  }
+  NonNullAttr(ASTContext &C, unsigned* arg_nums = 0, unsigned size = 0);
 
-  virtual ~NonNullAttr() {
-    delete [] ArgNums;
-  }
+  virtual void Destroy(ASTContext &C);
 
   typedef const unsigned *iterator;
   iterator begin() const { return ArgNums; }
index d835edf0b3248f1722f3932671057a5d3ae5c7f6..d13d4b326c33173a3dbb877c696b93715b2b68bf 100644 (file)
@@ -50,6 +50,22 @@ void FormatAttr::setType(ASTContext &C, llvm::StringRef type) {
   ReplaceString(C, type);
 }
 
+NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size)
+  : Attr(NonNull), ArgNums(0), Size(0) {  
+  if (size == 0)
+    return;
+  assert(arg_nums);
+  ArgNums = new (C) unsigned[size];
+  Size = size;
+  memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size);
+}
+
+void NonNullAttr::Destroy(ASTContext &C) {
+  if (ArgNums)
+    C.Deallocate(ArgNums);
+  Attr::Destroy(C);
+}
+
 #define DEF_SIMPLE_ATTR_CLONE(ATTR)                                     \
   Attr *ATTR##Attr::clone(ASTContext &C) const {                        \
     return ::new (C) ATTR##Attr;                                        \
@@ -132,7 +148,7 @@ Attr *SectionAttr::clone(ASTContext &C) const {
 }
 
 Attr *NonNullAttr::clone(ASTContext &C) const {
-  return ::new (C) NonNullAttr(ArgNums, Size);
+  return ::new (C) NonNullAttr(C, ArgNums, Size);
 }
 
 Attr *FormatAttr::clone(ASTContext &C) const {
index 29f5556b1934031315183c50dfe94cda7eb66783..6a93e6c265d7d52168f2641ab5cd125e0c5a00c9 100644 (file)
@@ -532,7 +532,7 @@ Attr *PCHReader::ReadAttributes() {
       llvm::SmallVector<unsigned, 16> ArgNums;
       ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
       Idx += Size;
-      New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
+      New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
       break;
     }
 
index e592fd2f5564bbda872ceb5d56ce4440869e8975..cba1e9e1cd508c86ed4d83f037f3c0ef4dbd8fd9 100644 (file)
@@ -307,7 +307,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   unsigned* start = &NonNullArgs[0];
   unsigned size = NonNullArgs.size();
   std::sort(start, start + size);
-  d->addAttr(::new (S.Context) NonNullAttr(start, size));
+  d->addAttr(::new (S.Context) NonNullAttr(S.Context, start, size));
 }
 
 static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) {