Don't add standard processors twice to routes from 2.X sessions. Fixes #3434.
[ardour.git] / libs / pbd / pool.cc
index abb8695c23016b56ce26aa781d844f5f5f9ecf1f..aac98a2c155540a15b6f9b07770b8610f8e3cf20 100644 (file)
@@ -157,7 +157,18 @@ free_per_thread_pool (void* ptr)
        CrossThreadPool* cp = static_cast<CrossThreadPool*> (ptr);
        assert (cp);
 
-       cp->parent()->add_to_trash (cp);
+       if (cp->empty()) {
+               /* This CrossThreadPool is already empty, and the thread is finishing so nothing
+                * more can be added to it.  We can just delete the pool.
+                */
+               delete cp;
+       } else {
+               /* This CrossThreadPool is not empty, meaning that there's some Events in it
+                * which another thread may yet read, so we can't delete the pool just yet.
+                * Put it in the trash and hope someone deals with it at some stage.
+                */
+               cp->parent()->add_to_trash (cp);
+       }
 }
  
 PerThreadPool::PerThreadPool ()