THRIFT-1184 event_base memory freeing by class TNonblockingServer
adds option to use existing event base
Patch: Pavlin Radoslavov

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1153307 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp
index 4774b36..89e9afd 100644
--- a/lib/cpp/src/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/server/TNonblockingServer.cpp
@@ -567,7 +567,7 @@
     delete connection;
   }
 
-  if (eventBase_) {
+  if (eventBase_ && ownEventBase_) {
     event_base_free(eventBase_);
   }
 
@@ -802,10 +802,11 @@
 /**
  * Register the core libevent events onto the proper base.
  */
-void TNonblockingServer::registerEvents(event_base* base) {
+void TNonblockingServer::registerEvents(event_base* base, bool ownEventBase) {
   assert(serverSocket_ != -1);
   assert(!eventBase_);
   eventBase_ = base;
+  ownEventBase_ = ownEventBase;
 
   // Print some libevent stats
   GlobalOutput.printf("libevent %s method %s",
@@ -911,7 +912,7 @@
   }
 
   // Initialize libevent core
-  registerEvents(static_cast<event_base*>(event_init()));
+  registerEvents(static_cast<event_base*>(event_init()), true);
 
   // Run the preServe event
   if (eventHandler_ != NULL) {