From cade0e6afaa5355762265dca1844871f0100d23e Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 13 Sep 2014 12:39:02 -0400 Subject: [PATCH] fixed race condition --- NetDb.cpp | 3 +++ NetDb.h | 1 + 2 files changed, 4 insertions(+) diff --git a/NetDb.cpp b/NetDb.cpp index f3719290..2202b718 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -751,6 +751,7 @@ namespace data if (it == m_RequestedDestinations.end ()) // not exist yet { RequestedDestination * d = new RequestedDestination (dest, isLeaseSet, isExploratory, pool); + std::unique_lock l(m_RequestedDestinationsMutex); m_RequestedDestinations[dest] = d; return d; } @@ -764,6 +765,7 @@ namespace data if (it != m_RequestedDestinations.end ()) { delete it->second; + std::unique_lock l(m_RequestedDestinationsMutex); m_RequestedDestinations.erase (it); return true; } @@ -774,6 +776,7 @@ namespace data { if (dest) { + std::unique_lock l(m_RequestedDestinationsMutex); m_RequestedDestinations.erase (dest->GetDestination ()); delete dest; } diff --git a/NetDb.h b/NetDb.h index 16513bd9..6ee065d4 100644 --- a/NetDb.h +++ b/NetDb.h @@ -110,6 +110,7 @@ namespace data std::map m_LeaseSets; std::map m_RouterInfos; std::vector m_Floodfills; + std::mutex m_RequestedDestinationsMutex; std::map m_RequestedDestinations; std::set m_Subscriptions;