Fix use-after-free in CommandCompletions.cpp
authorPavel Labath <labath@google.com>
Fri, 29 Jun 2018 10:27:18 +0000 (10:27 +0000)
committerPavel Labath <labath@google.com>
Fri, 29 Jun 2018 10:27:18 +0000 (10:27 +0000)
The code was creating a StringRef to a temporary std::string. The
solution is to just drop the .str() from the original StringRef.

This manifested it self as the new TestCompletions test failing in some
configurations.

llvm-svn: 335960

lldb/source/Commands/CommandCompletions.cpp

index dbb0b7e..f83a06d 100644 (file)
@@ -164,7 +164,7 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
     // search in the fully resolved directory, but CompletionBuffer keeps the
     // unmodified form that the user typed.
     Storage = Resolved;
-    llvm::StringRef RemainderDir = path::parent_path(Remainder.str());
+    llvm::StringRef RemainderDir = path::parent_path(Remainder);
     if (!RemainderDir.empty()) {
       // Append the remaining path to the resolved directory.
       Storage.append(path::get_separator());