Fix memory leak in connection graph

When generating virtual connections to represent bus aliases, we need to
store the pointers for future deletion otherwise we will leak the memory
This commit is contained in:
Seth Hillbrand 2023-10-06 09:09:51 -07:00
parent 1a5c515e45
commit 9260f58803
2 changed files with 21 additions and 2 deletions

View File

@ -1349,11 +1349,15 @@ void CONNECTION_GRAPH::generateBusAliasMembers()
wxString name = conn->FullLocalName(); wxString name = conn->FullLocalName();
CONNECTION_SUBGRAPH* new_sg = new CONNECTION_SUBGRAPH( this ); CONNECTION_SUBGRAPH* new_sg = new CONNECTION_SUBGRAPH( this );
// 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 ); SCH_CONNECTION* new_conn = new SCH_CONNECTION( item, subgraph->m_sheet );
new_conn->SetGraph( this ); new_conn->SetGraph( this );
new_conn->SetName( name ); new_conn->SetName( name );
new_conn->SetType( CONNECTION_TYPE::NET ); new_conn->SetType( CONNECTION_TYPE::NET );
subgraph->StoreImplicitConnection( new_conn );
int code = assignNewNetCode( *new_conn ); int code = assignNewNetCode( *new_conn );
wxLogTrace( ConnTrace, wxS( "SG(%ld), Adding full local name (%s) with sg (%d) on subsheet %s" ), subgraph->m_code, wxLogTrace( ConnTrace, wxS( "SG(%ld), Adding full local name (%s) with sg (%d) on subsheet %s" ), subgraph->m_code,

View File

@ -89,7 +89,11 @@ public:
m_hier_parent( nullptr ) m_hier_parent( nullptr )
{} {}
~CONNECTION_SUBGRAPH() = default; ~CONNECTION_SUBGRAPH()
{
for( SCH_CONNECTION* connection : m_bus_element_connections )
delete connection;
}
/** /**
* Determines which potential driver should drive the subgraph. * Determines which potential driver should drive the subgraph.
@ -162,6 +166,13 @@ public:
void RemoveItem( SCH_ITEM* aItem ); void RemoveItem( SCH_ITEM* aItem );
// 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 )
{
m_bus_element_connections.insert( aConnection );
}
private: private:
wxString driverName( SCH_ITEM* aItem ) const; wxString driverName( SCH_ITEM* aItem ) const;
@ -251,6 +262,10 @@ public:
/// A cache of escaped netnames from schematic items /// A cache of escaped netnames from schematic items
mutable std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache; mutable std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache;
/// A cache of connections that are part of this subgraph but that don't have
/// an owning element (i.e. bus members)
std::set<SCH_CONNECTION*> m_bus_element_connections;
}; };
struct NET_NAME_CODE_CACHE_KEY struct NET_NAME_CODE_CACHE_KEY