From 9f0b42cb3514f6fb46f820ea7144f5b50989cc02 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 17 Aug 2016 15:09:48 +0200 Subject: [PATCH] pns: fixed a few memleaks & conditional jumps depending on uninitalized variables --- common/geometry/shape_collisions.cpp | 47 ++++++++++++++-------------- pcbnew/router/pns_kicad_iface.cpp | 20 ++++++------ pcbnew/router/pns_node.cpp | 1 + pcbnew/router/pns_tool_base.cpp | 15 ++++----- 4 files changed, 43 insertions(+), 40 deletions(-) diff --git a/common/geometry/shape_collisions.cpp b/common/geometry/shape_collisions.cpp index 773dcc9a2d..b67c409a76 100644 --- a/common/geometry/shape_collisions.cpp +++ b/common/geometry/shape_collisions.cpp @@ -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; +} diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 167e9cc4e3..f353933c45 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -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 ); } diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index 80902b13bd..aac6e233f4 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -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 ) { diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 9905ff8711..5fe782a93d 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -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(); m_ctls = getViewControls();