================
@@ -182,29 +181,27 @@ template <typename Proto> class IOTransport : public 
JSONTransport<Proto> {
   using Message = typename JSONTransport<Proto>::Message;
   using MessageHandler = typename JSONTransport<Proto>::MessageHandler;
 
-  IOTransport(lldb::IOObjectSP in, lldb::IOObjectSP out)
-      : m_in(in), m_out(out) {}
+  IOTransport(MainLoop &loop, lldb::IOObjectSP in, lldb::IOObjectSP out)
+      : m_loop(loop), m_in(in), m_out(out) {}
 
   llvm::Error Send(const typename Proto::Evt &evt) override {
     return Write(evt);
   }
+
   llvm::Error Send(const typename Proto::Req &req) override {
     return Write(req);
   }
+
   llvm::Error Send(const typename Proto::Resp &resp) override {
     return Write(resp);
   }
 
-  llvm::Expected<MainLoop::ReadHandleUP>
-  RegisterMessageHandler(MainLoop &loop, MessageHandler &handler) override {
+  llvm::Error RegisterMessageHandler(MessageHandler &handler) override {
     Status status;
-    MainLoop::ReadHandleUP read_handle = loop.RegisterReadObject(
+    m_read_handle = m_loop.RegisterReadObject(
         m_in, [this, &handler](MainLoopBase &base) { OnRead(base, handler); },
         status);
-    if (status.Fail()) {
-      return status.takeError();
-    }
-    return read_handle;
+    return status.takeError();
   }
 
----------------
ashgti wrote:

The reason I keep it around is to ensure the MainLoop out lives the 
JSONTransport object. If we took a pointer or if we only call 
`RegisterReadObject` from `RegisterMessageHandler` we can end up with a 
transport out living the MainLoop which caused some crashes for me in the unit 
tests.

https://github.com/llvm/llvm-project/pull/179564
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to