From f3e13848fa6f773b3f4cb75649d38bf8fa21861f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 7 Apr 2023 19:37:30 +0200 Subject: [PATCH] Do not modify read-only RCU copy of routelist RCU reader returns a shared ptr to the current object which can also be used in other places at the same time. Sorting the shared-ptr list invalidates iterators which can throw off other users of the same object. This fixes a bug in PT-import which calls get_nth_audio_track(). --- libs/ardour/session.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index be2106049c..57354bb8ef 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -6408,11 +6408,11 @@ Session::route_removed_from_route_group (RouteGroup* rg, std::weak_ptr r) std::shared_ptr Session::get_nth_audio_track (uint32_t nth) const { - std::shared_ptr rl = routes.reader (); - rl->sort (Stripable::Sorter ()); + RouteList rl (*(routes.reader ())); + rl.sort (Stripable::Sorter()); - for (RouteList::const_iterator r = rl->begin(); r != rl->end(); ++r) { - std::shared_ptr at = std::dynamic_pointer_cast (*r); + for (auto const& r: rl) { + std::shared_ptr at = std::dynamic_pointer_cast (r); if (!at) { continue; }