From b1316dee7c0fff0954e8dd46d7910517b07d173b Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 5 Oct 2014 16:18:24 -0400 Subject: [PATCH] fixed race condition --- Tunnel.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index 18a6f811..10e5de14 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -422,9 +422,12 @@ namespace tunnel if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) { LogPrint ("Tunnel ", tunnel->GetTunnelID (), " expired"); - auto pool = tunnel->GetTunnelPool (); - if (pool) - pool->TunnelExpired (tunnel); + { + std::unique_lock l(m_PoolsMutex); + auto pool = tunnel->GetTunnelPool (); + if (pool) + pool->TunnelExpired (tunnel); + } { std::unique_lock l(m_OutboundTunnelsMutex); it = m_OutboundTunnels.erase (it); @@ -465,9 +468,12 @@ namespace tunnel if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) { LogPrint ("Tunnel ", tunnel->GetTunnelID (), " expired"); - auto pool = tunnel->GetTunnelPool (); - if (pool) - pool->TunnelExpired (tunnel); + { + std::unique_lock l(m_PoolsMutex); + auto pool = tunnel->GetTunnelPool (); + if (pool) + pool->TunnelExpired (tunnel); + } { std::unique_lock l(m_InboundTunnelsMutex); it = m_InboundTunnels.erase (it);