diff --git a/libi2pd_client/I2PService.cpp b/libi2pd_client/I2PService.cpp index e3d05022..c7d53bb5 100644 --- a/libi2pd_client/I2PService.cpp +++ b/libi2pd_client/I2PService.cpp @@ -67,9 +67,10 @@ namespace client { if(m_ConnectTimeout) m_ReadyTimer.cancel(); - std::unique_lock l(m_HandlersMutex); - for (auto it: m_Handlers) - it->Terminate (); + IterateHandlers ([](std::shared_ptr handler) + { + if (handler) handler->Terminate (); + }); m_Handlers.clear(); } diff --git a/libi2pd_client/I2PService.h b/libi2pd_client/I2PService.h index 5231a957..4cbb4631 100644 --- a/libi2pd_client/I2PService.h +++ b/libi2pd_client/I2PService.h @@ -74,6 +74,16 @@ namespace client virtual const char* GetName() const { return "Generic I2P Service"; } + protected: + + template + void IterateHandlers (Callback&& callback) + { + std::unique_lock l(m_HandlersMutex); + for (auto it: m_Handlers) + callback (it); + } + private: void TriggerReadyCheckTimer();