plug some memory leaks in libardour
[ardour.git] / libs / ardour / session.cc
index 3b03985ece78fe1203ba94ee9f40f2097fe98551..e9d85300b7da180492cd87644894810f4f128a9d 100644 (file)
 #include "ardour/source_factory.h"
 #include "ardour/speakers.h"
 #include "ardour/tempo.h"
+#include "ardour/ticker.h"
 #include "ardour/track.h"
 #include "ardour/user_bundle.h"
 #include "ardour/utils.h"
@@ -306,6 +307,7 @@ Session::Session (AudioEngine &eng,
        ,  _speakers (new Speakers)
        , _order_hint (-1)
        , ignore_route_processor_changes (false)
+       , midi_clock (0)
        , _scene_changer (0)
        , _midi_ports (0)
        , _mmc (0)
@@ -596,6 +598,7 @@ Session::destroy ()
 
        /* disconnect from any and all signals that we are connected to */
 
+       Port::PortSignalDrop (); /* EMIT SIGNAL */
        drop_connections ();
 
        /* shutdown control surface protocols while we still have ports
@@ -616,7 +619,6 @@ Session::destroy ()
         * callbacks from the engine any more.
         */
 
-       Port::PortSignalDrop (); /* EMIT SIGNAL */
        Port::PortDrop (); /* EMIT SIGNAL */
 
        ltc_tx_cleanup();
@@ -739,6 +741,7 @@ Session::destroy ()
        delete _midi_ports; _midi_ports = 0;
        delete _locations; _locations = 0;
 
+       delete midi_clock;
        delete _tempo_map;
 
        DEBUG_TRACE (DEBUG::Destruction, "Session::destroy() done\n");
@@ -1077,11 +1080,16 @@ Session::remove_monitor_section ()
        }
 
        remove_route (_monitor_out);
+       if (_state_of_the_state & Deletion) {
+               return;
+       }
+
        auto_connect_master_bus ();
 
        if (auditioner) {
                auditioner->connect ();
        }
+
        Config->ParameterChanged ("use-monitor-bus");
 }
 
@@ -3557,7 +3565,7 @@ Session::remove_routes (boost::shared_ptr<RouteList> routes_to_remove)
                resort_routes ();
 #endif
 
-       if (_process_graph) {
+       if (_process_graph && !(_state_of_the_state & Deletion)) {
                _process_graph->clear_other_chain ();
        }
 
@@ -3574,6 +3582,10 @@ Session::remove_routes (boost::shared_ptr<RouteList> routes_to_remove)
                (*iter)->drop_references ();
        }
 
+       if (_state_of_the_state & Deletion) {
+               return;
+       }
+
        Route::RemoteControlIDChange(); /* EMIT SIGNAL */
 
        /* save the new state of the world */