From c63b021e7d5fcd5eb298db974c84a409b5e2f045 Mon Sep 17 00:00:00 2001 From: Martin Chang Date: Sat, 18 Mar 2023 18:38:55 +0800 Subject: [PATCH] Hold shared pointer from the very beginning (#1537) --- lib/src/WebSocketConnectionImpl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/WebSocketConnectionImpl.cc b/lib/src/WebSocketConnectionImpl.cc index 7594726a..40ea2117 100644 --- a/lib/src/WebSocketConnectionImpl.cc +++ b/lib/src/WebSocketConnectionImpl.cc @@ -372,6 +372,7 @@ void WebSocketConnectionImpl::onNewMessage( const trantor::TcpConnectionPtr &connPtr, trantor::MsgBuffer *buffer) { + auto self = shared_from_this(); while (buffer->readableBytes() > 0) { auto success = parser_.parse(buffer); @@ -397,7 +398,7 @@ void WebSocketConnectionImpl::onNewMessage( } // LOG_TRACE << "new message received: " << message // << "\n(type=" << (int)type << ")"; - messageCallback_(std::move(message), shared_from_this(), type); + messageCallback_(std::move(message), self, type); } else {