Don't try to dereference a NULL ptr (the function 'ARDOUR::IO::nth()' can return...
authorJohn Emmas <johne53@tiscali.co.uk>
Tue, 27 Jan 2015 11:59:23 +0000 (11:59 +0000)
committerJohn Emmas <johne53@tiscali.co.uk>
Tue, 27 Jan 2015 11:59:23 +0000 (11:59 +0000)
Note 1: Potentially we could have the same issue with 'AutomationLine::nth()' (although the current code seems okay)

Note 2: This (specific) problem seems mostly to affect Mixbus3 when it tries to load an old (version2) session from Ardour2. Mixbus can mark certain IO ports as being 'unused'. While loading sessions, function 'ARDOUR::IO::ensure_ports_locked()' deletes any unused ports. But later, the function 'ARDOUR::IO::make_connections_2X()' was crashing while trying to connect those (now NULL) ports. This commit fixes that crash but there's some evidence that it might only have moved the problem elsewhere. The version2 sessions now open successfully - but an MSVC (Debug) build now crashes whilst closing them (the Release build however, is okay). Someone who's more familiar with the code than me should review the Mixbus3/Ardour2 loading procedure to make sure it's safe.

libs/ardour/audio_diskstream.cc
libs/ardour/io.cc

index d835c4a20fa89d166758fe28ee5855022cf6444d..4facf5db644d1d0c43fc28ba2b22021f0ddcdd4c 100644 (file)
@@ -225,7 +225,7 @@ AudioDiskstream::get_input_sources ()
 
                connections.clear ();
 
-               if (_io->nth (n)->get_connections (connections) == 0) {
+               if ((_io->nth (n).get()) && (_io->nth (n)->get_connections (connections) == 0)) {
                        if (!(*chan)->source.name.empty()) {
                                // _source->disable_metering ();
                        }
index 0d66da7795faf10853c96b7beabf9be55898ad62..5e9e5aa0c1a9accb7c9a48b3004e6a9deebc3095 100644 (file)
@@ -1040,7 +1040,8 @@ IO::make_connections_2X (const XMLNode& node, int /*version*/, bool in)
                                        if (p != string::npos) {
                                                ports[x].replace (p, 4, "/audio_out");
                                        }
-                                       nth(i)->connect (ports[x]);
+                                       if (NULL != nth(i).get())
+                                               nth(i)->connect (ports[x]);
                                }
                        }
 
@@ -1082,7 +1083,8 @@ IO::make_connections_2X (const XMLNode& node, int /*version*/, bool in)
                                        if (p != string::npos) {
                                                ports[x].replace (p, 3, "/audio_in");
                                        }
-                                       nth(i)->connect (ports[x]);
+                                       if (NULL != nth(i).get())
+                                               nth(i)->connect (ports[x]);
                                }
                        }
 
@@ -1606,8 +1608,10 @@ IO::connected_to (boost::shared_ptr<const IO> other) const
 
        for (i = 0; i < no; ++i) {
                for (j = 0; j < ni; ++j) {
-                       if (nth(i)->connected_to (other->nth(j)->name())) {
-                               return true;
+                       if ((NULL != nth(i).get()) && (NULL != other->nth(j).get())) {
+                               if (nth(i)->connected_to (other->nth(j)->name())) {
+                                       return true;
+                               }
                        }
                }
        }