fix (part of) memory leak on shutdown. See PR2975.
authorTorok Edwin <edwintorok@gmail.com>
Mon, 6 Apr 2009 20:49:21 +0000 (20:49 +0000)
committerTorok Edwin <edwintorok@gmail.com>
Mon, 6 Apr 2009 20:49:21 +0000 (20:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68457 91177308-0d34-0410-b5e6-96231b3b80d8

examples/HowToUseJIT/HowToUseJIT.cpp
lib/VMCore/Type.cpp

index 0482df6248fa9d5ee2928ec3f16f1205180c1e7b..b5c6d111914f36cc482efd76bd0ff7fd2addcf83 100644 (file)
@@ -42,6 +42,7 @@
 #include "llvm/ExecutionEngine/JIT.h"
 #include "llvm/ExecutionEngine/Interpreter.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
@@ -109,5 +110,8 @@ int main() {
 
   // Import result of execution:
   outs() << "Result: " << gv.IntVal << "\n";
+  EE->freeMachineCodeForFunction(FooF);
+  delete EE;
+  llvm_shutdown();
   return 0;
 }
index c14d5119e5da0a3cd33e246166e0dcc7ddcdf78a..f0ee04ae24754e8d0e5dde71f3a9368f42ef000a 100644 (file)
@@ -666,6 +666,22 @@ protected:
   std::multimap<unsigned, PATypeHolder> TypesByHash;
 
 public:
+  ~TypeMapBase()
+  {
+    for (std::multimap<unsigned, PATypeHolder>::iterator I
+         = TypesByHash.begin(), E = TypesByHash.end(); I != E;) {
+      Type *Ty = I->second.get();
+      if (!Ty->isAbstract() && (isa<PointerType>(Ty) || isa<FunctionType>(Ty) ||
+                                isa<VectorType>(Ty))) {
+        TypesByHash.erase(I++);
+        // PATypeHolder won't destroy it, so we must
+        Ty->destroy();
+      }
+      else
+        ++I;
+    }
+  }
+
   void RemoveFromTypesByHash(unsigned Hash, const Type *Ty) {
     std::multimap<unsigned, PATypeHolder>::iterator I =
       TypesByHash.lower_bound(Hash);