session_shared: mutex lock in BackendClass::release_backend MP-550
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 2 Jun 2014 09:19:58 +0000 (11:19 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 2 Jun 2014 09:19:58 +0000 (11:19 +0200)
src/filter_session_shared.cpp

index d14dc1b..eb8b23a 100644 (file)
@@ -305,27 +305,29 @@ void yf::SessionShared::BackendClass::release_backend(BackendInstancePtr b)
 
 void yf::SessionShared::BackendClass::remove_backend(BackendInstancePtr b)
 {
-    BackendInstanceList::iterator it = m_backend_list.begin();
-
-    while (it != m_backend_list.end())
     {
-        if (*it == b)
+        boost::mutex::scoped_lock lock(m_mutex_backend_class);
+        BackendInstanceList::iterator it = m_backend_list.begin();
+        for (;;)
         {
-             mp::odr odr;
-            (*it)->m_close_package->response() = odr.create_close(
-                0, Z_Close_lackOfActivity, 0);
-            (*it)->m_close_package->session().close();
-            (*it)->m_close_package->move();
-
-            it = m_backend_list.erase(it);
-        }
-        else
+            if (it == m_backend_list.end())
+                return;
+            if (*it == b)
+            {
+                it = m_backend_list.erase(it);
+                break;
+            }
             it++;
+        }
     }
+    mp::odr odr;
+    b->m_close_package->response() = odr.create_close(
+        0, Z_Close_lackOfActivity, 0);
+    b->m_close_package->session().close();
+    b->m_close_package->move();
 }
 
 
-
 yf::SessionShared::BackendInstancePtr
 yf::SessionShared::BackendClass::get_backend(
     const mp::Package &frontend_package)