diff options
author | David Reiss <dreiss@apache.org> | 2010-09-02 15:26:28 +0000 |
---|---|---|
committer | David Reiss <dreiss@apache.org> | 2010-09-02 15:26:28 +0000 |
commit | 8ede81860c5b6c93645c62e871c213b4188e7162 (patch) | |
tree | 2e9325beccc0da26967f2be2a39ad552b8bd3ee8 | |
parent | 383e9495667afbd686beb89bb510433fdd4cfe82 (diff) | |
download | thrift-8ede81860c5b6c93645c62e871c213b4188e7162.tar.gz |
THRIFT-798. cpp: Reduce resource leakage by TNonblockingServer destructor
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@991980 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | lib/cpp/src/server/TNonblockingServer.cpp | 23 | ||||
-rw-r--r-- | lib/cpp/src/server/TNonblockingServer.h | 2 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp index eeb3e69a2..85fe26575 100644 --- a/lib/cpp/src/server/TNonblockingServer.cpp +++ b/lib/cpp/src/server/TNonblockingServer.cpp @@ -521,6 +521,29 @@ void TConnection::checkIdleBufferMemLimit(size_t limit) { } } +TNonblockingServer::~TNonblockingServer() { + // TODO: We currently leak any active TConnection objects. + // Since we're shutting down and destroying the event_base, the TConnection + // objects will never receive any additional callbacks. (And even if they + // did, it would be bad, since they keep a pointer around to the server, + // which is being destroyed.) + + // Clean up unused TConnection objects in connectionStack_ + while (!connectionStack_.empty()) { + TConnection* connection = connectionStack_.top(); + connectionStack_.pop(); + delete connection; + } + + if (eventBase_) { + event_base_free(eventBase_); + } + + if (serverSocket_ >= 0) { + close(serverSocket_); + } +} + /** * Creates a new connection either by reusing an object off the stack or * by allocating a new one entirely diff --git a/lib/cpp/src/server/TNonblockingServer.h b/lib/cpp/src/server/TNonblockingServer.h index 70f46c6dd..2dd53629a 100644 --- a/lib/cpp/src/server/TNonblockingServer.h +++ b/lib/cpp/src/server/TNonblockingServer.h @@ -243,7 +243,7 @@ class TNonblockingServer : public TServer { setThreadManager(threadManager); } - ~TNonblockingServer() {} + ~TNonblockingServer(); void setThreadManager(boost::shared_ptr<ThreadManager> threadManager); |