From e9e836ac83c61c80d60c9ade5a9d39abaed4160a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 28 Dec 2021 18:29:35 +0100 Subject: [PATCH] Fix crash when unlinking dplus --- DPlusProtocolHandlerPool.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/DPlusProtocolHandlerPool.cpp b/DPlusProtocolHandlerPool.cpp index c29bf83..db464a8 100644 --- a/DPlusProtocolHandlerPool.cpp +++ b/DPlusProtocolHandlerPool.cpp @@ -61,14 +61,14 @@ CDPlusProtocolHandler* CDPlusProtocolHandlerPool::getHandler(unsigned int port) if (proto) { if (proto->open()) { m_pool[port] = proto; - CLog::logInfo("New CDPlusProtocolHandler now on UDP port %u.\n", port); + CLog::logInfo("New D Plus Protocol Handler now on UDP port %u.\n", port); } else { delete proto; proto = NULL; - CLog::logInfo("ERROR: Can't open new DPlus UDP port %u!\n", port); + CLog::logError("Can't open new DPlus UDP port %u!\n", port); } } else - CLog::logInfo("ERROR: Can't allocate new CDPlusProtocolHandler at port %u\n", port); + CLog::logError("Can't allocate new DPlus ProtocolHandler at port %u\n", port); return proto; } @@ -77,15 +77,16 @@ void CDPlusProtocolHandlerPool::release(CDPlusProtocolHandler *handler) assert(handler != NULL); for (auto it=m_pool.begin(); it!=m_pool.end(); it++) { if (it->second == handler) { - it->second->close(); - delete it->second; - CLog::logInfo("Releasing CDPlusProtocolHandler on port %u.\n", it->first); m_pool.erase(it); + handler->close(); + delete handler; + m_index = m_pool.end(); // m_index might be ut of order so reset it + CLog::logInfo("Releasing DPlus ProtocolHandler on port %u.\n", it->first); return; } } // we should never get here! - CLog::logInfo("ERROR: could not find CDPlusProtocolHander (port=%u) to release!\n", handler->getPort()); + CLog::logInfo("ERROR: could not find DPlus ProtocolHander (port=%u) to release!\n", handler->getPort()); } DPLUS_TYPE CDPlusProtocolHandlerPool::read()