abort if configuration fails
[ardour.git] / libs / ardour / control_protocol_manager.cc
index b97c89b80999bb9fd2d78a8467f3f5492adc1abc..7423d3b5c6a4c82ac464b1fd2d4b26c56d254369 100644 (file)
@@ -193,6 +193,18 @@ int
 ControlProtocolManager::teardown (ControlProtocolInfo& cpi)
 {
        if (!cpi.protocol) {
+
+               /* we could still have a descriptor even if the protocol was
+                  never instantiated. Close the associated module (shared
+                  object/DLL) and make sure we forget about it.
+               */
+
+               if (cpi.descriptor) {
+                       cerr << "Closing descriptor for CPI anyway\n";
+                       delete (Glib::Module*) cpi.descriptor->module;
+                       cpi.descriptor = 0;
+               }
+
                return 0;
        }
 
@@ -223,10 +235,15 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi)
        }
 
        cpi.protocol = 0;
+
        delete cpi.state;
        cpi.state = 0;
-       delete (Glib::Module*)cpi.descriptor->module;
-       cpi.descriptor->module = 0;
+       delete (Glib::Module*) cpi.descriptor->module;
+       /* cpi->descriptor is now inaccessible since dlclose() or equivalent
+        * has been performed, and the descriptor is (or could be) a static
+        * object made accessible by dlopen().
+        */
+       cpi.descriptor = 0;
 
        ProtocolStatusChange (&cpi);