From: Rafael Espindola <rafael.espindola@gmail.com>
Date: Tue, 26 May 2015 01:52:19 +0000 (+0000)
Subject: Move MCSection destruction to MCContext::reset.
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=eac71e23fdf56fd8a908d15c30d846ba50145489;p=oota-llvm.git

Move MCSection destruction to MCContext::reset.

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
---

diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp
index 0a453cdb46b..1f2f034a3ac 100644
--- a/lib/MC/MCContext.cpp
+++ b/lib/MC/MCContext.cpp
@@ -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();