[llvm-commits] CVS: llvm/lib/Linker/LinkArchives.cpp

Reid Spencer reid at x10sys.com
Mon Nov 15 22:47:52 PST 2004



Changes in directory llvm/lib/Linker:

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

Per code review:\
* Adjust indentation\
* Ensure memory do not leak if exceptions happen (std::auto_ptr use)

---
Diffs of the changes:  (+13 -11)

Index: llvm/lib/Linker/LinkArchives.cpp
diff -u llvm/lib/Linker/LinkArchives.cpp:1.35 llvm/lib/Linker/LinkArchives.cpp:1.36
--- llvm/lib/Linker/LinkArchives.cpp:1.35	Tue Nov 16 00:40:54 2004
+++ llvm/lib/Linker/LinkArchives.cpp	Tue Nov 16 00:47:41 2004
@@ -163,9 +163,9 @@
 ///  FALSE - No errors.
 ///
 bool llvm::LinkInArchive(Module *M,
-                          const std::string &Filename,
-                          std::string* ErrorMessage,
-                          bool Verbose)
+                         const std::string &Filename,
+                         std::string* ErrorMessage,
+                         bool Verbose)
 {
   // Find all of the symbols currently undefined in the bytecode program.
   // If all the symbols are defined, the program is complete, and there is
@@ -179,13 +179,16 @@
 
   // Open the archive file
   if (Verbose) std::cerr << "  Loading archive file '" << Filename << "'\n";
-  Archive* arch = Archive::OpenAndLoadSymbols(sys::Path(Filename));
+  std::auto_ptr<Archive> AutoArch (
+    Archive::OpenAndLoadSymbols(sys::Path(Filename)));
+
+  Archive* arch = AutoArch.get();
 
   // While we are linking in object files, loop.
   while (true) {     
     std::set<ModuleProvider*> Modules;
     // Find the modules we need to link
-    arch->findModulesDefiningSymbols(UndefinedSymbols,Modules);
+    arch->findModulesDefiningSymbols(UndefinedSymbols, Modules);
 
     // If we didn't find any more modules to link this time, we are done.
     if (Modules.empty())
@@ -195,14 +198,13 @@
     for (std::set<ModuleProvider*>::iterator I=Modules.begin(), E=Modules.end();
          I != E; ++I) {
       // Get the module we must link in.
-      std::auto_ptr<Module> aModule((*I)->releaseModule());
+      std::auto_ptr<Module> AutoModule( (*I)->releaseModule() );
+
+      Module* aModule = AutoModule.get();
 
-      // Link it in.
-      if (LinkModules(M, aModule.get(), ErrorMessage)) {
-        // don't create a memory leak
-        delete arch;
+      // Link it in
+      if (LinkModules(M, aModule, ErrorMessage))
         return true;   // Couldn't link in the right object file...        
-      }
     }
 
     // We have linked in a set of modules determined by the archive to satisfy






More information about the llvm-commits mailing list