<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 30, 2014 at 12:03 PM, Simon Atanasyan <span dir="ltr"><<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: atanasyan<br>
Date: Wed Apr 30 14:03:56 2014<br>
New Revision: 207690<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=207690&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=207690&view=rev</a><br>
Log:<br>
[ELF] Return result from the function ASAP.<br>
<br>
No functional changes.<br>
<br>
Modified:<br>
    lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=207690&r1=207689&r2=207690&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=207690&r1=207689&r2=207690&view=diff</a><br>

==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Wed Apr 30 14:03:56 2014<br>
@@ -226,30 +226,20 @@ static void buildSearchPath(SmallString<<br>
 }<br>
<br>
 ErrorOr<StringRef> ELFLinkingContext::searchLibrary(StringRef libName) const {<br>
-  bool foundFile = false;<br>
-  StringRef pathref;<br>
   SmallString<128> path;<br>
   for (StringRef dir : _inputSearchPaths) {<br>
     // Search for dynamic library<br>
     if (!_isStaticExecutable) {<br>
       buildSearchPath(path, dir, _sysrootPath);<br>
       llvm::sys::path::append(path, Twine("lib") + libName + ".so");<br>
-      pathref = path.str();<br>
-      if (llvm::sys::fs::exists(pathref)) {<br>
-        foundFile = true;<br>
-      }<br>
+      if (llvm::sys::fs::exists(path.str()))<br>
+        return StringRef(*new (_allocator) std::string(path.str()));<br></blockquote><div><br></div><div>I don't think this commit introduces a leak, but how does this not leak memory?  BumpPtrAllocator doesn't call the destructors of things allocated in it.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     }<br>
     // Search for static libraries too<br>
-    if (!foundFile) {<br>
-      buildSearchPath(path, dir, _sysrootPath);<br>
-      llvm::sys::path::append(path, Twine("lib") + libName + ".a");<br>
-      pathref = path.str();<br>
-      if (llvm::sys::fs::exists(pathref)) {<br>
-        foundFile = true;<br>
-      }<br>
-    }<br>
-    if (foundFile)<br>
-      return StringRef(*new (_allocator) std::string(pathref));<br>
+    buildSearchPath(path, dir, _sysrootPath);<br>
+    llvm::sys::path::append(path, Twine("lib") + libName + ".a");<br>
+    if (llvm::sys::fs::exists(path.str()))<br>
+      return StringRef(*new (_allocator) std::string(path.str()));<br>
   }<br>
   if (!llvm::sys::fs::exists(libName))<br>
     return llvm::make_error_code(llvm::errc::no_such_file_or_directory);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>