[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp

Reid Spencer reid at x10sys.com
Mon Nov 15 22:41:16 PST 2004



Changes in directory llvm/lib/Bytecode/Reader:

ReaderWrappers.cpp updated: 1.35 -> 1.36
---
Log message:

Per code review:\
* Get rid of memory leaks on exception \
* Provide better comments of how the memory handling works

---
Diffs of the changes:  (+12 -8)

Index: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
diff -u llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.35 llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.36
--- llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.35	Sun Nov 14 19:20:11 2004
+++ llvm/lib/Bytecode/Reader/ReaderWrappers.cpp	Tue Nov 16 00:41:05 2004
@@ -377,13 +377,12 @@
     std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fName.get()));
 
     // Get the module from the provider
-    Module* M = AMP->releaseModule();
+    Module* M = AMP->materializeModule();
 
     // Get the symbols
     getSymbols(M, symbols);
 
     // Done with the module
-    delete M;
     return true;
 
   } catch (...) {
@@ -393,12 +392,13 @@
 
 ModuleProvider* 
 llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
-                              const std::string& ModuleID,
-                              std::vector<std::string>& symbols) {
+                         const std::string& ModuleID,
+                         std::vector<std::string>& symbols) {
 
+  ModuleProvider* MP = 0;
   try {
-    ModuleProvider* MP = 
-      getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
+    // Get the module provider
+    MP = getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
 
     // Get the module from the provider
     Module* M = MP->materializeModule();
@@ -406,11 +406,15 @@
     // Get the symbols
     getSymbols(M, symbols);
 
-    // Done with the module
+    // Done with the module. Note that ModuleProvider will delete the
+    // Module when it is deleted. Also note that its the caller's responsibility
+    // to delete the ModuleProvider.
     return MP;
 
   } catch (...) {
-    // Fall through
+    // We only delete the ModuleProvider here because its destructor will
+    // also delete the Module (we used materializeModule not releaseModule).
+    delete MP;
   }
   return 0;
 }






More information about the llvm-commits mailing list