From 9c5758958c28cdb9452741d626560eff9d2c7e40 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 2 Nov 2015 17:34:01 +0100 Subject: [PATCH] Fix crash in JsonRpcClient::DataAvailableHandler fixes #10495 --- lib/remote/httpclientconnection.cpp | 3 ++- lib/remote/httpserverconnection.cpp | 3 ++- lib/remote/jsonrpcconnection.cpp | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/remote/httpclientconnection.cpp b/lib/remote/httpclientconnection.cpp index bcc834ded..ba7237253 100644 --- a/lib/remote/httpclientconnection.cpp +++ b/lib/remote/httpclientconnection.cpp @@ -62,7 +62,8 @@ void HttpClientConnection::Reconnect(void) /* m_Stream = new NetworkStream(socket); -- does not currently work because the NetworkStream class doesn't support async I/O */ - m_Stream->RegisterDataHandler(boost::bind(&HttpClientConnection::DataAvailableHandler, this, _1)); + /* the stream holds an owning reference to this object through the callback we're registering here */ + m_Stream->RegisterDataHandler(boost::bind(&HttpClientConnection::DataAvailableHandler, HttpClientConnection::Ptr(this), _1)); if (m_Stream->IsDataAvailable()) DataAvailableHandler(m_Stream); } diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index 5160ef1dd..044983b71 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -55,7 +55,8 @@ void HttpServerConnection::StaticInitialize(void) void HttpServerConnection::Start(void) { - m_Stream->RegisterDataHandler(boost::bind(&HttpServerConnection::DataAvailableHandler, this)); + /* the stream holds an owning reference to this object through the callback we're registering here */ + m_Stream->RegisterDataHandler(boost::bind(&HttpServerConnection::DataAvailableHandler, HttpServerConnection::Ptr(this))); if (m_Stream->IsDataAvailable()) DataAvailableHandler(); } diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index 19471d10c..715fb21e4 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -60,7 +60,8 @@ void JsonRpcConnection::StaticInitialize(void) void JsonRpcConnection::Start(void) { - m_Stream->RegisterDataHandler(boost::bind(&JsonRpcConnection::DataAvailableHandler, this)); + /* the stream holds an owning reference to this object through the callback we're registering here */ + m_Stream->RegisterDataHandler(boost::bind(&JsonRpcConnection::DataAvailableHandler, JsonRpcConnection::Ptr(this))); if (m_Stream->IsDataAvailable()) DataAvailableHandler(); } @@ -103,7 +104,7 @@ void JsonRpcConnection::SendMessage(const Dictionary::Ptr& message) Log(LogWarning, "JsonRpcConnection") << info.str() << "\n" << DiagnosticInformation(ex); - Utility::QueueAsyncCallback(boost::bind(&JsonRpcConnection::Disconnect, JsonRpcConnection::Ptr(this))); + Disconnect(); } } -- 2.40.0