OSDN Git Service

fix ticket #33102 (fix memory reak).
authorMichiro Hibari <l05102@shibaura-it.ac.jp>
Mon, 24 Feb 2014 06:01:20 +0000 (15:01 +0900)
committerMichiro Hibari <l05102@shibaura-it.ac.jp>
Mon, 24 Feb 2014 06:01:20 +0000 (15:01 +0900)
l7vsd/include/virtualservice.h
l7vsd/src/l7vsd.cpp

index da06cd3..5aeb190 100644 (file)
@@ -621,6 +621,8 @@ public:
         void run();
         void stop();
 
+        boost::shared_ptr<boost::thread> vs_thread_ptr;
+
         void connection_active(const boost::asio::ip::tcp::endpoint &);
         void connection_inactive(const boost::asio::ip::tcp::endpoint &);
         void release_session(const tcp_session *session_ptr);
index a5eff71..33b4d89 100644 (file)
@@ -249,7 +249,7 @@ void    l7vsd::add_virtual_service(const virtualservice_element *in_vselement, e
                 try {
 
                         // create thread and run
-                        vs_threads.create_thread(boost::bind(&virtual_service::run, vsptr));
+                        (*vsptr).vs_thread_ptr =  boost::shared_ptr<boost::thread>(vs_threads.create_thread(boost::bind(&virtual_service::run, vsptr)));
 
                 } catch (...) {
                         std::stringstream    buf;
@@ -348,6 +348,8 @@ void    l7vsd::del_virtual_service(const virtualservice_element *in_vselement, e
         if (vslist.end() !=  vsitr) {
                 // vs stop
                 (*vsitr)->stop();
+                (*vsitr)->vs_thread_ptr->join();
+                vs_threads.remove_thread((*vsitr)->vs_thread_ptr.get());
                 // vs finalize
                 (*vsitr)->finalize(err);