Move MCSection destruction to MCContext::reset.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 May 2015 01:52:19 +0000 (01:52 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 May 2015 01:52:19 +0000 (01:52 +0000)
Fixes the leaks when running llc.

Also found by an asan bot.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238167 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCContext.cpp

index 0a453cdb46b71bed4555c22d513bb5fd08c14693..1f2f034a3acba468bd75b2e15affac86de1a0890 100644 (file)
@@ -55,14 +55,6 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
 }
 
 MCContext::~MCContext() {
-  // Call the destructors so the fragments are freed
-  for (auto &I : ELFUniquingMap)
-    I.second->~MCSectionELF();
-  for (auto &I : COFFUniquingMap)
-    I.second->~MCSectionCOFF();
-  for (auto &I : MachOUniquingMap)
-    I.second->~MCSectionMachO();
-
   if (AutoReset)
     reset();
 
@@ -78,6 +70,14 @@ MCContext::~MCContext() {
 //===----------------------------------------------------------------------===//
 
 void MCContext::reset() {
+  // Call the destructors so the fragments are freed
+  for (auto &I : ELFUniquingMap)
+    I.second->~MCSectionELF();
+  for (auto &I : COFFUniquingMap)
+    I.second->~MCSectionCOFF();
+  for (auto &I : MachOUniquingMap)
+    I.second->~MCSectionMachO();
+
   UsedNames.clear();
   Symbols.clear();
   Allocator.Reset();