]> granicus.if.org Git - icinga2/commitdiff
Fix crash in JsonRpcClient::DataAvailableHandler
authorGunnar Beutner <gunnar@beutner.name>
Mon, 2 Nov 2015 16:34:01 +0000 (17:34 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 2 Nov 2015 16:45:44 +0000 (17:45 +0100)
fixes #10495

lib/remote/httpclientconnection.cpp
lib/remote/httpserverconnection.cpp
lib/remote/jsonrpcconnection.cpp

index bcc834ded41064c18fafd85d6522f5706b34ebb8..ba7237253a65985fa918f09f8228a9e38f51f4c1 100644 (file)
@@ -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);
 }
index 5160ef1dd98cafceef636a34e76312d280607de9..044983b713bc0ffd318ee5bad669e8fc2db74b5a 100644 (file)
@@ -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();
 }
index 19471d10c8edf8e16ecd26f51fc9554b287375ca..715fb21e4e90d8a49e73fb59e986801b45712c05 100644 (file)
@@ -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();
        }
 }