Fix cleanup, lock source-list, emit SourceRemoved

This fixes various cases where SessionHandleRef shared_ptr<>
were kept when sources were removed.
This commit is contained in:
Robin Gareus 2020-02-25 15:32:17 +01:00
parent 28c141d450
commit 53a6b3e28d
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04

View file

@ -3375,7 +3375,7 @@ Session::cleanup_sources (CleanupReport& rep)
{
// FIXME: needs adaptation to midi
vector<boost::shared_ptr<Source> > dead_sources;
SourceList dead_sources;
string audio_path;
string midi_path;
vector<string> candidates;
@ -3391,6 +3391,8 @@ Session::cleanup_sources (CleanupReport& rep)
_state_of_the_state = StateOfTheState (_state_of_the_state | InCleanup);
Glib::Threads::Mutex::Lock ls (source_lock, Glib::Threads::NOT_LOCK);
/* this is mostly for windows which doesn't allow file
* renaming if the file is in use. But we don't special
* case it because we need to know if this causes
@ -3418,6 +3420,7 @@ Session::cleanup_sources (CleanupReport& rep)
rep.paths.clear ();
rep.space = 0;
ls.acquire ();
for (SourceMap::iterator i = sources.begin(); i != sources.end(); ) {
SourceMap::iterator tmp;
@ -3431,11 +3434,11 @@ Session::cleanup_sources (CleanupReport& rep)
if (!i->second->used() && (i->second->length(i->second->natural_position()) > 0)) {
dead_sources.push_back (i->second);
i->second->drop_references ();
}
i = tmp;
}
ls.release ();
/* build a list of all the possible audio directories for the session */
@ -3476,6 +3479,7 @@ Session::cleanup_sources (CleanupReport& rep)
/* add our current source list
*/
ls.acquire ();
for (SourceMap::iterator i = sources.begin(); i != sources.end(); ) {
boost::shared_ptr<FileSource> fs;
SourceMap::iterator tmp = i;
@ -3523,12 +3527,21 @@ Session::cleanup_sources (CleanupReport& rep)
* reference to it.
*/
dead_sources.push_back (i->second);
sources.erase (i);
}
}
i = tmp;
}
ls.release ();
for (SourceList::iterator i = dead_sources.begin(); i != dead_sources.end(); ++i) {
/* The following triggers Region::source_deleted (), which
* causes regions to drop the given source */
(*i)->drop_references ();
SourceRemoved (*i); /* EMIT SIGNAL */
}
/* now check each candidate source to see if it exists in the list of
* sources_used_by_all_snapshots. If it doesn't, put it into "unused".
@ -3661,7 +3674,10 @@ Session::cleanup_sources (CleanupReport& rep)
rep.space += statbuf.st_size;
}
/* dump the history list */
/* drop last Source references */
dead_sources.clear ();
/* dump the history list, remove references */
_history.clear ();