Fix memory mgmt issue with SOLID shapes

We don't delete items from the CTOR but we do need to check if they
exist in the incoming SOLID before cloning

Fixes https://gitlab.com/kicad/code/kicad/issues/5214
This commit is contained in:
Seth Hillbrand 2020-08-17 06:14:33 -07:00
parent cff76e55d5
commit 5c3a1d059e
1 changed files with 11 additions and 12 deletions

View File

@ -44,19 +44,22 @@ public:
~SOLID() ~SOLID()
{ {
delete m_shape; delete m_shape;
delete m_alternateShape;
} }
SOLID( const SOLID& aSolid ) : SOLID( const SOLID& aSolid ) :
ITEM( aSolid ) ITEM( aSolid )
{ {
if( m_shape ) if( aSolid.m_shape )
delete m_shape; m_shape = aSolid.m_shape->Clone();
else
m_shape = nullptr;
if( m_alternateShape ) if( aSolid.m_alternateShape )
delete m_alternateShape; m_alternateShape = aSolid.m_alternateShape->Clone();
else
m_alternateShape = nullptr;
m_shape = aSolid.m_shape->Clone();
m_alternateShape = aSolid.m_alternateShape->Clone();
m_pos = aSolid.m_pos; m_pos = aSolid.m_pos;
m_padToDie = aSolid.m_padToDie; m_padToDie = aSolid.m_padToDie;
} }
@ -79,17 +82,13 @@ public:
void SetShape( SHAPE* shape ) void SetShape( SHAPE* shape )
{ {
if( m_shape ) delete m_shape;
delete m_shape;
m_shape = shape; m_shape = shape;
} }
void SetAlternateShape( SHAPE* shape ) void SetAlternateShape( SHAPE* shape )
{ {
if( m_alternateShape ) delete m_alternateShape;
delete m_alternateShape;
m_alternateShape = shape; m_alternateShape = shape;
} }