[lldb-vscode] Fix dangling pointer in request_evaluate.

SBError::GetCString() returns a pointer to a string owned by the SBError
object. The code here was calling GetCString on a temporary and using
the returned pointer after the temporary was destroyed.

Differential Revision: https://reviews.llvm.org/D59400

llvm-svn: 356227
This commit is contained in:
Jorge Gorbe Moya 2019-03-15 01:46:50 +00:00
parent e8710ef1fb
commit 717b1c804b
1 changed files with 4 additions and 1 deletions

View File

@ -965,7 +965,10 @@ void request_evaluate(const llvm::json::Object &request) {
value = frame.EvaluateExpression(expression.data());
if (value.GetError().Fail()) {
response["success"] = llvm::json::Value(false);
const char *error_cstr = value.GetError().GetCString();
// This error object must live until we're done with the pointer returned
// by GetCString().
lldb::SBError error = value.GetError();
const char *error_cstr = error.GetCString();
if (error_cstr && error_cstr[0])
EmplaceSafeString(response, "message", std::string(error_cstr));
else