From ce95c9fb097d16fe3029b958f2ed7893ffebb5ab Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 6 May 2022 00:33:44 +0200 Subject: [PATCH] Fix std::set< BackendPortPtr> lookup by key The set uses a custom sort-by-name comparator. Previously it was possible to have an inconsistent set iterator. std::set::find() did not find a given port while std::find() did. This fixes using std::set::find() on the PortIndex set. --- libs/ardour/port_engine_shared.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/ardour/port_engine_shared.cc b/libs/ardour/port_engine_shared.cc index a9c2accaf1..c4966240e7 100644 --- a/libs/ardour/port_engine_shared.cc +++ b/libs/ardour/port_engine_shared.cc @@ -542,7 +542,16 @@ PortEngineSharedImpl::set_port_name (PortEngine::PortHandle port_handle, const s } const std::string old_name = port->name(); - int ret = port->set_name (newname); + + /* PortIndex std::set is sorted by name, using the name as key. + * So name-changes need to update the set + */ + RCUWriter index_writer (_ports); + boost::shared_ptr ps = index_writer.get_copy (); + + ps->erase (port); + int ret = port->set_name (newname); + ps->insert (port); if (ret == 0) {