Commit e8bb7d1e authored by Wayne Stambaugh's avatar Wayne Stambaugh

Fix segfault when replacing an existing component in a library.

parent b1ffd179
...@@ -344,18 +344,24 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent, ...@@ -344,18 +344,24 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent,
wxASSERT( aNewComponent != NULL ); wxASSERT( aNewComponent != NULL );
wxASSERT( aOldComponent->GetName().CmpNoCase( aNewComponent->GetName() )== 0 ); wxASSERT( aOldComponent->GetName().CmpNoCase( aNewComponent->GetName() )== 0 );
/* Remove the old root component. The component will automatically be removed when all /* Remove the old root component. The component will automatically be deleted
* it's aliases are deleted. * when all it's aliases are deleted. Do not place any code that accesses
* aOldComponent inside this loop that gets evaluated after the last alias is
* removed in RemoveEntry(). Failure to heed this warning will result in a
* segfault.
*/ */
BOOST_FOREACH( LIB_ALIAS* alias, aOldComponent->m_aliases ) size_t i = aOldComponent->m_aliases.size();
while( i != 0 )
{ {
RemoveEntry( (CMP_LIB_ENTRY*) alias ); i -= 1;
RemoveEntry( (CMP_LIB_ENTRY*) aOldComponent->m_aliases[ i ] );
} }
LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this ); LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this );
// Add new aliases to library alias map. // Add new aliases to library alias map.
for( size_t i = 0; i < newCmp->m_aliases.size(); i++ ) for( i = 0; i < newCmp->m_aliases.size(); i++ )
{ {
aliases[ newCmp->m_aliases[ i ]->GetName() ] = newCmp->m_aliases[ i ]; aliases[ newCmp->m_aliases[ i ]->GetName() ] = newCmp->m_aliases[ i ];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment