Fix race condition in TCPServerDispatcher.cpp

This commit is contained in:
Conor Burgess 2018-01-12 18:11:31 +00:00 committed by Günter Obiltschnig
parent 7eb1325bba
commit 603a6e23da

View File

@ -96,7 +96,7 @@ void TCPServerDispatcher::release()
void TCPServerDispatcher::run()
{
AutoPtr<TCPServerDispatcher> guard(this, true); // ensure object stays alive
AutoPtr<TCPServerDispatcher> guard(this, false); // ensure _rc is decreased when function exits
int idleTime = (int) _pParams->getThreadIdleTime().totalMilliseconds();
@ -149,6 +149,10 @@ void TCPServerDispatcher::enqueue(const StreamSocket& socket)
{
_threadPool.startWithPriority(_pParams->getThreadPriority(), *this, threadName);
++_currentThreads;
// Ensure this object lives at least until run() starts
// Small chance of leaking if threadpool is stopped before this
// work runs, but better than a dangling pointer and crash!
duplicate();
}
catch (Poco::Exception&)
{