From 92f963b85810ae15c87730dbccce72d868bda79b Mon Sep 17 00:00:00 2001 From: Conor Burgess Date: Tue, 13 Mar 2018 14:10:22 +0000 Subject: [PATCH] Poco 1.9.1 version of #2088 (#2219) --- Net/src/TCPServerDispatcher.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Net/src/TCPServerDispatcher.cpp b/Net/src/TCPServerDispatcher.cpp index 5cdc4098e..ee2f36b33 100644 --- a/Net/src/TCPServerDispatcher.cpp +++ b/Net/src/TCPServerDispatcher.cpp @@ -96,7 +96,7 @@ void TCPServerDispatcher::release() void TCPServerDispatcher::run() { - AutoPtr guard(this, true); // ensure object stays alive + AutoPtr guard(this); // ensure _rc is decreased when function exits; it was incremented in enqueue() 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! + ++_rc; } catch (Poco::Exception&) {