diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index e3e2bc23ff..1d73fa5db3 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -1746,17 +1746,18 @@ void CONNECTION_GRAPH::generateBusAliasMembers() // This connection cannot form a part of the item because the item is not, itself // connected to this subgraph. It exists as part of a virtual item that may be // connected to other items but is not in the schematic. - SCH_CONNECTION* new_conn = new SCH_CONNECTION( item, subgraph->m_sheet ); + auto new_conn = std::make_unique( item, subgraph->m_sheet ); new_conn->SetGraph( this ); new_conn->SetName( name ); new_conn->SetType( CONNECTION_TYPE::NET ); - subgraph->StoreImplicitConnection( new_conn ); - int code = assignNewNetCode( *new_conn ); + + SCH_CONNECTION* new_conn_ptr = subgraph->StoreImplicitConnection( std::move( new_conn ) ); + int code = assignNewNetCode( *new_conn_ptr ); wxLogTrace( ConnTrace, wxS( "SG(%ld), Adding full local name (%s) with sg (%d) on subsheet %s" ), subgraph->m_code, name, code, subgraph->m_sheet.PathHumanReadable() ); - new_sg->m_driver_connection = new_conn; + new_sg->m_driver_connection = new_conn_ptr; new_sg->m_code = m_last_subgraph_code++; new_sg->m_sheet = subgraph->GetSheet(); new_sg->m_is_bus_member = true; diff --git a/eeschema/connection_graph.h b/eeschema/connection_graph.h index d34ad6013b..b949d97ce4 100644 --- a/eeschema/connection_graph.h +++ b/eeschema/connection_graph.h @@ -22,6 +22,7 @@ #ifndef _CONNECTION_GRAPH_H #define _CONNECTION_GRAPH_H +#include #include #include #include @@ -93,11 +94,6 @@ public: m_driver_connection( nullptr ) {} - ~CONNECTION_SUBGRAPH() - { - for( SCH_CONNECTION* connection : m_bus_element_connections ) - delete connection; - } friend class CONNECTION_GRAPH; @@ -219,9 +215,13 @@ public: // Use this to keep a connection pointer that is not owned by any item // This will be destroyed with the subgraph - void StoreImplicitConnection( SCH_CONNECTION* aConnection ) + SCH_CONNECTION* StoreImplicitConnection( std::unique_ptr aConnection ) { - m_bus_element_connections.insert( aConnection ); + SCH_CONNECTION* raw = aConnection.get(); + + m_bus_element_connections.insert( std::move( aConnection ) ); + + return raw; } private: @@ -317,9 +317,19 @@ private: /// Cache for driver connection. SCH_CONNECTION* m_driver_connection; + // A comparator for unique_ptr to allow storage in a set + struct CompareConnectionPtr + { + bool operator()( const std::unique_ptr& aLeft, + const std::unique_ptr& aRight ) const + { + return aLeft.get() < aRight.get(); + } + }; + /// A cache of connections that are part of this subgraph but that don't have /// an owning element (i.e. bus members) - std::set m_bus_element_connections; + std::set, CompareConnectionPtr> m_bus_element_connections; std::mutex m_driver_mutex; };