From 81a7253e0f32710fadd5d5e4b4ab44045ba75e56 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 22 Sep 2014 13:28:46 -0400 Subject: [PATCH] fixed crash on termination --- NTCPSession.cpp | 49 ++++++++++++++++++++++++++++++++++--------------- Transports.cpp | 14 ++++++++------ 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index b0e8b211..56aa49f5 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -35,6 +35,9 @@ namespace ntcp delete m_DHKeysPair; if (m_NextMessage) i2p::DeleteI2NPMessage (m_NextMessage); + for (auto it :m_DelayedMessages) + i2p::DeleteI2NPMessage (it); + m_DelayedMessages.clear (); } void NTCPSession::CreateAESKey (uint8_t * pubKey, uint8_t * aesKey) @@ -144,7 +147,8 @@ namespace ntcp if (ecode) { LogPrint ("Couldn't send Phase 1 message: ", ecode.message ()); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + Terminate (); } else { @@ -160,7 +164,8 @@ namespace ntcp if (ecode) { LogPrint ("Phase 1 read error: ", ecode.message ()); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + Terminate (); } else { @@ -215,7 +220,8 @@ namespace ntcp if (ecode) { LogPrint ("Couldn't send Phase 2 message: ", ecode.message ()); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + Terminate (); } else { @@ -231,10 +237,13 @@ namespace ntcp if (ecode) { LogPrint ("Phase 2 read error: ", ecode.message (), ". Wrong ident assumed"); - GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid - i2p::transports.ReuseDHKeysPair (m_DHKeysPair); - m_DHKeysPair = nullptr; - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + { + GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid + i2p::transports.ReuseDHKeysPair (m_DHKeysPair); + m_DHKeysPair = nullptr; + Terminate (); + } } else { @@ -291,7 +300,8 @@ namespace ntcp if (ecode) { LogPrint ("Couldn't send Phase 3 message: ", ecode.message ()); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + Terminate (); } else { @@ -307,7 +317,8 @@ namespace ntcp if (ecode) { LogPrint ("Phase 3 read error: ", ecode.message ()); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + Terminate (); } else { @@ -356,7 +367,8 @@ namespace ntcp if (ecode) { LogPrint ("Couldn't send Phase 4 message: ", ecode.message ()); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + Terminate (); } else { @@ -373,8 +385,11 @@ namespace ntcp if (ecode) { LogPrint ("Phase 4 read error: ", ecode.message ()); - GetRemoteRouterInfo ().SetUnreachable (true); // this router doesn't like us - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + { + GetRemoteRouterInfo ().SetUnreachable (true); // this router doesn't like us + Terminate (); + } } else { @@ -418,7 +433,8 @@ namespace ntcp if (ecode) { LogPrint ("Read error: ", ecode.message ()); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + Terminate (); } else { @@ -604,8 +620,11 @@ namespace ntcp if (ecode) { LogPrint ("Connect error: ", ecode.message ()); - GetRemoteRouterInfo ().SetUnreachable (true); - Terminate (); + if (ecode != boost::asio::error::operation_aborted) + { + GetRemoteRouterInfo ().SetUnreachable (true); + Terminate (); + } } else { diff --git a/Transports.cpp b/Transports.cpp index b36d266a..2a3ba83e 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -135,6 +135,7 @@ namespace i2p { m_SSUServer->Stop (); delete m_SSUServer; + m_SSUServer = nullptr; } for (auto session: m_NTCPSessions) @@ -149,7 +150,7 @@ namespace i2p { m_Thread->join (); delete m_Thread; - m_Thread = 0; + m_Thread = nullptr; } } @@ -188,13 +189,14 @@ namespace i2p conn->ServerLogin (); } else - { delete conn; - } - conn = new i2p::ntcp::NTCPServerConnection (m_Service); - m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this, - conn, boost::asio::placeholders::error)); + if (error != boost::asio::error::operation_aborted) + { + conn = new i2p::ntcp::NTCPServerConnection (m_Service); + m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this, + conn, boost::asio::placeholders::error)); + } } i2p::ntcp::NTCPSession * Transports::GetNextNTCPSession ()