Fix ELF Writter related memory leaks
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Tue, 1 Sep 2009 19:25:52 +0000 (19:25 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Tue, 1 Sep 2009 19:25:52 +0000 (19:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80717 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/ELFWriter.cpp

index b1842ff3dc7972e32cea6734566357c0966dfaf1..55a2f7006434a107cdc3f774a9a3d1d9b86e2670 100644 (file)
@@ -93,6 +93,24 @@ ELFWriter::ELFWriter(raw_ostream &o, TargetMachine &tm)
 ELFWriter::~ELFWriter() {
   delete ElfCE;
   delete &OutContext;
+
+  while(!SymbolList.empty()) {
+    delete SymbolList.back(); 
+    SymbolList.pop_back();
+  }
+
+  while(!PrivateSyms.empty()) {
+    delete PrivateSyms.back(); 
+    PrivateSyms.pop_back();
+  }
+
+  while(!SectionList.empty()) {
+    delete SectionList.back(); 
+    SectionList.pop_back();
+  }
+
+  // Release the name mangler object.
+  delete Mang; Mang = 0;
 }
 
 // doInitialization - Emit the file header and all of the global variables for
@@ -714,13 +732,6 @@ bool ELFWriter::doFinalization(Module &M) {
   // Dump the sections and section table to the .o file.
   OutputSectionsAndSectionTable();
 
-  // We are done with the abstract symbols.
-  SymbolList.clear();
-  SectionList.clear();
-  NumSections = 0;
-
-  // Release the name mangler object.
-  delete Mang; Mang = 0;
   return false;
 }