From de6dd770465809d500dd682fb5425df8a965f7ce Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 13 Dec 2015 10:51:43 -0500 Subject: [PATCH] use shared_ptr for LeaseSet request --- Destination.cpp | 16 ++++++---------- Destination.h | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 6e2550eb..826af4ef 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -94,7 +94,8 @@ namespace client if (m_IsRunning) Stop (); for (auto it: m_LeaseSetRequests) - delete it.second; + if (it.second->requestComplete) it.second->requestComplete (nullptr); + m_LeaseSetRequests.clear (); if (m_Pool) i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool); if (m_DatagramDestination) @@ -299,7 +300,6 @@ namespace client { it1->second->requestTimeoutTimer.cancel (); if (it1->second->requestComplete) it1->second->requestComplete (leaseSet); - delete it1->second; m_LeaseSetRequests.erase (it1); } } @@ -312,7 +312,7 @@ namespace client auto it = m_LeaseSetRequests.find (key); if (it != m_LeaseSetRequests.end ()) { - LeaseSetRequest * request = it->second; + auto request = it->second; bool found = false; if (request->excluded.size () < MAX_NUM_FLOODFILLS_PER_REQUEST) { @@ -340,7 +340,6 @@ namespace client if (!found) { if (request->requestComplete) request->requestComplete (nullptr); - delete request; m_LeaseSetRequests.erase (key); } } @@ -540,16 +539,15 @@ namespace client auto floodfill = i2p::data::netdb.GetClosestFloodfill (dest, excluded); if (floodfill) { - LeaseSetRequest * request = new LeaseSetRequest (m_Service); + auto request = std::make_shared (m_Service); request->requestComplete = requestComplete; - auto ret = m_LeaseSetRequests.insert (std::pair(dest,request)); + auto ret = m_LeaseSetRequests.insert (std::pair >(dest,request)); if (ret.second) // inserted { if (!SendLeaseSetRequest (dest, floodfill, request)) { // request failed if (request->requestComplete) request->requestComplete (nullptr); - delete request; m_LeaseSetRequests.erase (dest); } } @@ -558,7 +556,6 @@ namespace client LogPrint (eLogError, "Request of ", dest.ToBase64 (), " is pending already"); // TODO: queue up requests if (request->requestComplete) request->requestComplete (nullptr); - delete request; } } else @@ -566,7 +563,7 @@ namespace client } bool ClientDestination::SendLeaseSetRequest (const i2p::data::IdentHash& dest, - std::shared_ptr nextFloodfill, LeaseSetRequest * request) + std::shared_ptr nextFloodfill, std::shared_ptr request) { auto replyTunnel = m_Pool->GetNextInboundTunnel (); if (!replyTunnel) LogPrint (eLogError, "No inbound tunnels found"); @@ -631,7 +628,6 @@ namespace client if (done) { if (it->second->requestComplete) it->second->requestComplete (nullptr); - delete it->second; m_LeaseSetRequests.erase (it); } } diff --git a/Destination.h b/Destination.h index 0000014b..aa7123e7 100644 --- a/Destination.h +++ b/Destination.h @@ -118,7 +118,7 @@ namespace client void HandleDeliveryStatusMessage (std::shared_ptr msg); void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete); - bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr nextFloodfill, LeaseSetRequest * request); + bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr nextFloodfill, std::shared_ptr request); void HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest); void HandleCleanupTimer (const boost::system::error_code& ecode); void CleanupRemoteLeaseSets (); @@ -132,7 +132,7 @@ namespace client i2p::data::PrivateKeys m_Keys; uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; std::map > m_RemoteLeaseSets; - std::map m_LeaseSetRequests; + std::map > m_LeaseSetRequests; std::shared_ptr m_Pool; std::shared_ptr m_LeaseSet;