pns: fixed a few memleaks & conditional jumps depending on uninitalized variables

This commit is contained in:
Maciej Suminski 2016-08-17 15:09:48 +02:00
parent 7909de6127
commit 9f0b42cb35
4 changed files with 43 additions and 40 deletions

View File

@ -466,31 +466,32 @@ bool SHAPE::Collide( const SHAPE* aShape, int aClerance ) const
return CollideShapes( this, aShape, aClerance, false, dummy );
}
bool SHAPE_RECT::Collide( const SEG& aSeg, int aClearance ) const
{
//VECTOR2I pmin = VECTOR2I( std::min( aSeg.a.x, aSeg.b.x ), std::min( aSeg.a.y, aSeg.b.y ) );
//VECTOR2I pmax = VECTOR2I( std::max( aSeg.a.x, aSeg.b.x ), std::max( aSeg.a.y, aSeg.b.y ));
//BOX2I r( pmin, VECTOR2I( pmax.x - pmin.x, pmax.y - pmin.y ) );
//if( BBox( 0 ).SquaredDistance( r ) > aClearance * aClearance )
// return false;
if( BBox( 0 ).Contains( aSeg.A ) || BBox( 0 ).Contains( aSeg.B ) )
return true;
VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
VECTOR2I( m_p0.x, m_p0.y + m_h ),
VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
VECTOR2I( m_p0.x + m_w, m_p0.y ),
VECTOR2I( m_p0.x, m_p0.y ) };
for( int i = 0; i < 4; i++ )
{
//VECTOR2I pmin = VECTOR2I( std::min( aSeg.a.x, aSeg.b.x ), std::min( aSeg.a.y, aSeg.b.y ) );
//VECTOR2I pmax = VECTOR2I( std::max( aSeg.a.x, aSeg.b.x ), std::max( aSeg.a.y, aSeg.b.y ));
//BOX2I r( pmin, VECTOR2I( pmax.x - pmin.x, pmax.y - pmin.y ) );
SEG s( vts[i], vts[i + 1], i );
//if( BBox( 0 ).SquaredDistance( r ) > aClearance * aClearance )
// return false;
if( BBox( 0 ).Contains( aSeg.A ) || BBox( 0 ).Contains( aSeg.B ) )
if( s.Distance( aSeg ) < aClearance )
return true;
VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
VECTOR2I( m_p0.x, m_p0.y + m_h ),
VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
VECTOR2I( m_p0.x + m_w, m_p0.y ),
VECTOR2I( m_p0.x, m_p0.y ) };
for( int i = 0; i < 4; i++ )
{
SEG s( vts[i], vts[i + 1], i );
if( s.Distance( aSeg ) < aClearance )
return true;
}
return false;
}
return false;
}

View File

@ -295,6 +295,7 @@ public:
~PNS_PCBNEW_DEBUG_DECORATOR()
{
Clear();
delete m_items;
}
void SetView( KIGFX::VIEW* aView )
@ -416,11 +417,14 @@ PNS_KICAD_IFACE::PNS_KICAD_IFACE()
PNS_KICAD_IFACE::~PNS_KICAD_IFACE()
{
if( m_ruleResolver )
delete m_ruleResolver;
delete m_ruleResolver;
delete m_debugDecorator;
if( m_debugDecorator )
delete m_debugDecorator;
if( m_previewItems )
{
m_previewItems->FreeItems();
delete m_previewItems;
}
}
@ -741,9 +745,7 @@ void PNS_KICAD_IFACE::SyncWorld( PNS_NODE *aWorld )
int worstClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
if( m_ruleResolver )
delete m_ruleResolver;
delete m_ruleResolver;
m_ruleResolver = new PNS_PCBNEW_RULE_RESOLVER( m_board, m_router );
aWorld->SetRuleResolver( m_ruleResolver );
@ -892,9 +894,7 @@ void PNS_KICAD_IFACE::SetView( KIGFX::VIEW *aView )
m_view->Add( m_previewItems );
m_previewItems->ViewSetVisible( true );
if( m_debugDecorator )
delete m_debugDecorator;
delete m_debugDecorator;
m_debugDecorator = new PNS_PCBNEW_DEBUG_DECORATOR();
m_debugDecorator->SetView( m_view );
}

View File

@ -205,6 +205,7 @@ struct PNS_NODE::DEFAULT_OBSTACLE_VISITOR : public PNS_OBSTACLE_VISITOR
m_kindMask( aKindMask ),
m_limitCount( -1 ),
m_matchCount( 0 ),
m_extraClearance( 0 ),
m_differentNetsOnly( aDifferentNetsOnly ),
m_forceClearance( -1 )
{

View File

@ -68,7 +68,10 @@ TOOL_ACTION PNS_TOOL_BASE::ACT_RouterOptions( "pcbnew.InteractiveRouter.RouterOp
PNS_TOOL_BASE::PNS_TOOL_BASE( const std::string& aToolName ) :
TOOL_INTERACTIVE( aToolName )
{
m_gridHelper = NULL;
m_iface = NULL;
m_router = NULL;
m_startItem = NULL;
m_startLayer = 0;
@ -83,20 +86,18 @@ PNS_TOOL_BASE::PNS_TOOL_BASE( const std::string& aToolName ) :
PNS_TOOL_BASE::~PNS_TOOL_BASE()
{
delete m_router;
delete m_gridHelper;
delete m_iface;
delete m_router;
}
void PNS_TOOL_BASE::Reset( RESET_REASON aReason )
{
if( m_router )
delete m_router;
if( m_gridHelper)
delete m_gridHelper;
delete m_gridHelper;
delete m_iface;
delete m_router;
m_frame = getEditFrame<PCB_EDIT_FRAME>();
m_ctls = getViewControls();