[lld] r234120 - [elf] Fix a silly memory leak. std::string has a non-trivial dtor.

Benjamin Kramer benny.kra at googlemail.com
Sun Apr 5 08:53:20 PDT 2015


Author: d0k
Date: Sun Apr  5 10:53:20 2015
New Revision: 234120

URL: http://llvm.org/viewvc/llvm-project?rev=234120&view=rev
Log:
[elf] Fix a silly memory leak. std::string has a non-trivial dtor.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=234120&r1=234119&r2=234120&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Sun Apr  5 10:53:20 2015
@@ -128,7 +128,7 @@ ErrorOr<StringRef> ELFLinkingContext::se
                                         ? libName.drop_front()
                                         : Twine("lib", libName) + ".so");
       if (exists(path.str()))
-        return StringRef(*new (_allocator) std::string(path.str()));
+        return path.str().copy(_allocator);
     }
     // Search for static libraries too
     buildSearchPath(path, dir, _sysrootPath);
@@ -136,7 +136,7 @@ ErrorOr<StringRef> ELFLinkingContext::se
                                       ? libName.drop_front()
                                       : Twine("lib", libName) + ".a");
     if (exists(path.str()))
-      return StringRef(*new (_allocator) std::string(path.str()));
+      return path.str().copy(_allocator);
   }
   if (hasColonPrefix && exists(libName.drop_front()))
       return libName.drop_front();
@@ -151,7 +151,7 @@ ErrorOr<StringRef> ELFLinkingContext::se
     path.assign(_sysrootPath);
     path.append(fileName);
     if (exists(path.str()))
-      return StringRef(*new (_allocator) std::string(path.str()));
+      return path.str().copy(_allocator);
   } else if (exists(fileName)) {
     return fileName;
   }
@@ -163,7 +163,7 @@ ErrorOr<StringRef> ELFLinkingContext::se
     buildSearchPath(path, dir, _sysrootPath);
     llvm::sys::path::append(path, fileName);
     if (exists(path.str()))
-      return StringRef(*new (_allocator) std::string(path.str()));
+      return path.str().copy(_allocator);
   }
   return make_error_code(llvm::errc::no_such_file_or_directory);
 }





More information about the llvm-commits mailing list