[llvm-commits] [llvm] r119721 - /llvm/trunk/lib/VMCore/Attributes.cpp

Owen Anderson resistor at mac.com
Thu Nov 18 10:59:13 PST 2010


Author: resistor
Date: Thu Nov 18 12:59:13 2010
New Revision: 119721

URL: http://llvm.org/viewvc/llvm-project?rev=119721&view=rev
Log:
Fix an order-of-deallocation issue where the AttrListImpl could be deallocated before the global
LLVMContext, causing memory errors.  Patch by Peter Collingbourne.

Modified:
    llvm/trunk/lib/VMCore/Attributes.cpp

Modified: llvm/trunk/lib/VMCore/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Attributes.cpp?rev=119721&r1=119720&r2=119721&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Attributes.cpp (original)
+++ llvm/trunk/lib/VMCore/Attributes.cpp Thu Nov 18 12:59:13 2010
@@ -106,6 +106,11 @@
 // AttributeListImpl Definition
 //===----------------------------------------------------------------------===//
 
+namespace llvm {
+  class AttributeListImpl;
+}
+
+static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
 
 namespace llvm {
 static ManagedStatic<sys::SmartMutex<true> > ALMutex;
@@ -131,6 +136,8 @@
   }
   void DropRef() {
     sys::SmartScopedLock<true> Lock(*ALMutex);
+    if (!AttributesLists.isConstructed())
+      return;
     sys::cas_flag new_val = --RefCount;
     if (new_val == 0)
       delete this;
@@ -147,8 +154,6 @@
 };
 }
 
-static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
-
 AttributeListImpl::~AttributeListImpl() {
   // NOTE: Lock must be acquired by caller.
   AttributesLists->RemoveNode(this);





More information about the llvm-commits mailing list