Fix memory leaks in CONNECTION_GRAPH

Fixes #3692
This commit is contained in:
Jon Evans 2020-01-07 00:12:37 -05:00
parent 2c00540ad6
commit b4cc28a5b6
2 changed files with 22 additions and 4 deletions

View File

@ -355,7 +355,7 @@ bool CONNECTION_GRAPH::m_allowRealTime = true;
void CONNECTION_GRAPH::Reset()
{
for( auto subgraph : m_subgraphs )
for( auto& subgraph : m_subgraphs )
delete subgraph;
m_items.clear();
@ -1415,10 +1415,20 @@ void CONNECTION_GRAPH::buildConnectionGraph()
m_net_code_to_subgraphs_map[ code ].push_back( subgraph );
}
// Clean up and deallocate stale subgraphs
m_subgraphs.erase( std::remove_if( m_subgraphs.begin(), m_subgraphs.end(),
[&] ( const CONNECTION_SUBGRAPH* sg ) {
return sg->m_absorbed;
} ), m_subgraphs.end() );
[&]( const CONNECTION_SUBGRAPH* sg ) {
if( sg->m_absorbed )
{
delete sg;
return true;
}
else
{
return false;
}
} ),
m_subgraphs.end() );
}

View File

@ -76,6 +76,9 @@ public:
m_no_connect( nullptr ), m_bus_entry( nullptr ), m_driver( nullptr ), m_frame( aFrame ),
m_driver_connection( nullptr ), m_hier_parent( nullptr )
{}
~CONNECTION_SUBGRAPH() = default;
/**
* Determines which potential driver should drive the subgraph.
*
@ -206,6 +209,11 @@ public:
m_frame( aFrame )
{}
~CONNECTION_GRAPH()
{
Reset();
}
void Reset();
/**