From 2c76a4f0408d54cbc351375f60554a80cf01c941 Mon Sep 17 00:00:00 2001 From: Oceankenny Date: Thu, 3 Nov 2016 10:44:53 +0800 Subject: [PATCH] Fix a crash issue that happened when 1. sio_socket was removed within socket::impl::on_close and destructed. 2. WaitHandler of m_connection_timer(sio_socket::impl::on_close) is triggered although the timer 3. crash when trying to access members of sio_socket::impl since it has been destructed. --- src/sio_socket.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/sio_socket.cpp b/src/sio_socket.cpp index b48134e9..537d75af 100644 --- a/src/sio_socket.cpp +++ b/src/sio_socket.cpp @@ -157,6 +157,7 @@ namespace sio void ack(int msgId,string const& name,message::list const& ack_message); + void timeout_close(const boost::system::error_code& error); void timeout_connection(const boost::system::error_code &ec); void send_connect(); @@ -293,7 +294,7 @@ namespace sio } boost::system::error_code ec; m_connection_timer->expires_from_now(boost::posix_time::milliseconds(3000), ec); - m_connection_timer->async_wait(lib::bind(&socket::impl::on_close, this)); + m_connection_timer->async_wait(std::bind(&socket::impl::timeout_close, this, std::placeholders::_1)); } } @@ -324,6 +325,17 @@ namespace sio } } + void socket::impl::timeout_close(const boost::system::error_code& error) { + NULL_GUARD(m_client); + if(error) + { + return; + } + m_connection_timer.reset(); + LOG("Close timeout,close socket."<on_close(); + } + void socket::impl::on_close() { NULL_GUARD(m_client);