Skip to content

Commit fe40ea9

Browse files
authored
Merge pull request pocoproject#2088 from Burgch/tcpserverdispatcher-race
Fix race condition in TCPServerDispatcher.cpp
2 parents f7b73fb + 505282f commit fe40ea9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Net/src/TCPServerDispatcher.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void TCPServerDispatcher::release()
9292

9393
void TCPServerDispatcher::run()
9494
{
95-
AutoPtr<TCPServerDispatcher> guard(this, true); // ensure object stays alive
95+
AutoPtr<TCPServerDispatcher> guard(this, false); // ensure _rc is decreased when function exits
9696

9797
int idleTime = (int) _pParams->getThreadIdleTime().totalMilliseconds();
9898

@@ -144,6 +144,10 @@ void TCPServerDispatcher::enqueue(const StreamSocket& socket)
144144
{
145145
_threadPool.startWithPriority(_pParams->getThreadPriority(), *this, threadName);
146146
++_currentThreads;
147+
// Ensure this object lives at least until run() starts
148+
// Small chance of leaking if threadpool is stopped before this
149+
// work runs, but better than a dangling pointer and crash!
150+
duplicate();
147151
}
148152
catch (Poco::Exception&)
149153
{

0 commit comments

Comments
 (0)