THRIFT-3955 TThreadedServer Memory Leak
Client: C++
Patch: tzongw@gmail.com

This closes #1117
diff --git a/lib/cpp/src/thrift/server/TThreadedServer.cpp b/lib/cpp/src/thrift/server/TThreadedServer.cpp
index 9de1db8..c413be1 100644
--- a/lib/cpp/src/thrift/server/TThreadedServer.cpp
+++ b/lib/cpp/src/thrift/server/TThreadedServer.cpp
@@ -117,9 +117,10 @@
 
 void TThreadedServer::onClientConnected(const shared_ptr<TConnectedClient>& pClient) {
   Synchronized sync(clientMonitor_);
-  ClientMap::iterator it = activeClientMap_.insert(ClientMap::value_type(pClient.get(), boost::make_shared<TConnectedClientRunner>(pClient))).first;
-  boost::shared_ptr<apache::thrift::concurrency::Thread> pThread = threadFactory_->newThread(it->second);
-  it->second->setThread(pThread);
+  boost::shared_ptr<TConnectedClientRunner> pRunnable = boost::make_shared<TConnectedClientRunner>(pClient);
+  boost::shared_ptr<Thread> pThread = threadFactory_->newThread(pRunnable);
+  pRunnable->thread(pThread);
+  activeClientMap_.insert(ClientMap::value_type(pClient.get(), pThread));
   pThread->start();
 }
 
@@ -142,20 +143,11 @@
 TThreadedServer::TConnectedClientRunner::~TConnectedClientRunner() {
 }
 
-void TThreadedServer::TConnectedClientRunner::join() {
-  pThread_->join();
-}
-
 void TThreadedServer::TConnectedClientRunner::run() /* override */ {
   pClient_->run();  // Run the client
   pClient_.reset(); // The client is done - release it here rather than in the destructor for safety
 }
 
-void TThreadedServer::TConnectedClientRunner::setThread(
-    const boost::shared_ptr<apache::thrift::concurrency::Thread>& pThread) {
-  pThread_ = pThread;
-}
-
 }
 }
 } // apache::thrift::server
diff --git a/lib/cpp/src/thrift/server/TThreadedServer.h b/lib/cpp/src/thrift/server/TThreadedServer.h
index 758d1d9..56da901 100644
--- a/lib/cpp/src/thrift/server/TThreadedServer.h
+++ b/lib/cpp/src/thrift/server/TThreadedServer.h
@@ -116,17 +116,14 @@
   public:
     TConnectedClientRunner(const boost::shared_ptr<TConnectedClient>& pClient);
     virtual ~TConnectedClientRunner();
-    void join();
     void run() /* override */;
-    void setThread(const boost::shared_ptr<apache::thrift::concurrency::Thread>& pThread);
   private:
     boost::shared_ptr<TConnectedClient> pClient_;
-    boost::shared_ptr<apache::thrift::concurrency::Thread> pThread_;
   };
 
   apache::thrift::concurrency::Monitor clientMonitor_;
 
-  typedef std::map<TConnectedClient *, boost::shared_ptr<TConnectedClientRunner> > ClientMap;
+  typedef std::map<TConnectedClient *, boost::shared_ptr<apache::thrift::concurrency::Thread> > ClientMap;
 
   /**
    * A map of active clients