Fix memory leak in FOOTPRINT

We had some copy/pasta in the points group and lost dangling pointers
from a move operation.  Potentially a cause of heap corruption

Also set the parser to skip null fields on load

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22623
This commit is contained in:
Seth Hillbrand
2026-01-05 18:38:48 -08:00
parent 2cde69c506
commit e0633ea9ce
2 changed files with 23 additions and 2 deletions
+20 -2
View File
@@ -887,7 +887,7 @@ FOOTPRINT& FOOTPRINT::operator=( FOOTPRINT&& aOther )
for( PCB_POINT* point : m_points )
delete point;
m_groups.clear();
m_points.clear();
for( PCB_POINT* point : aOther.Points() )
Add( point );
@@ -948,6 +948,9 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
std::map<EDA_ITEM*, EDA_ITEM*> ptrMap;
// Copy fields
for( PCB_FIELD* field : m_fields )
delete field;
m_fields.clear();
for( PCB_FIELD* field : aOther.m_fields )
@@ -958,6 +961,9 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
}
// Copy pads
for( PAD* pad : m_pads )
delete pad;
m_pads.clear();
for( PAD* pad : aOther.Pads() )
@@ -968,6 +974,9 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
}
// Copy zones
for( ZONE* zone : m_zones )
delete zone;
m_zones.clear();
for( ZONE* zone : aOther.Zones() )
@@ -984,6 +993,9 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
}
// Copy drawings
for( BOARD_ITEM* item : m_drawings )
delete item;
m_drawings.clear();
for( BOARD_ITEM* item : aOther.GraphicalItems() )
@@ -994,6 +1006,9 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
}
// Copy groups
for( PCB_GROUP* group : m_groups )
delete group;
m_groups.clear();
for( PCB_GROUP* group : aOther.Groups() )
@@ -1007,7 +1022,10 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
Add( newGroup );
}
// Copy drawings
// Copy points
for( PCB_POINT* point : m_points )
delete point;
m_points.clear();
for( PCB_POINT* point : aOther.Points() )
@@ -1225,6 +1225,9 @@ void PCB_IO_KICAD_SEXPR::format( const FOOTPRINT* aFootprint ) const
for( const PCB_FIELD* field : aFootprint->GetFields() )
{
if( !field )
continue;
m_out->Print( "(property %s %s",
m_out->Quotew( field->GetCanonicalName() ).c_str(),
m_out->Quotew( field->GetText() ).c_str() );