[Lldb-commits] [lldb] r356227 - [lldb-vscode] Fix dangling pointer in request_evaluate.

Jorge Gorbe Moya via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 14 18:46:50 PDT 2019


Author: jgorbe
Date: Thu Mar 14 18:46:50 2019
New Revision: 356227

URL: http://llvm.org/viewvc/llvm-project?rev=356227&view=rev
Log:
[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

Modified:
    lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp

Modified: lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp?rev=356227&r1=356226&r2=356227&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp (original)
+++ lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp Thu Mar 14 18:46:50 2019
@@ -965,7 +965,10 @@ void request_evaluate(const llvm::json::
       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




More information about the lldb-commits mailing list