Author: dreiss
Date: Thu Sep  2 15:26:28 2010
New Revision: 991980

URL: http://svn.apache.org/viewvc?rev=991980&view=rev
Log:
THRIFT-798. cpp: Reduce resource leakage by TNonblockingServer destructor

Modified:
    incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
    incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h

Modified: incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp?rev=991980&r1=991979&r2=991980&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp Thu Sep  2 
15:26:28 2010
@@ -521,6 +521,29 @@ void TConnection::checkIdleBufferMemLimi
   }
 }
 
+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

Modified: incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h?rev=991980&r1=991979&r2=991980&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h Thu Sep  2 
15:26:28 2010
@@ -243,7 +243,7 @@ class TNonblockingServer : public TServe
     setThreadManager(threadManager);
   }
 
-  ~TNonblockingServer() {}
+  ~TNonblockingServer();
 
   void setThreadManager(boost::shared_ptr<ThreadManager> threadManager);
 


Reply via email to