From 721949b50ec79b27584c72a47d756555c4ba5a26 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 10 Mar 2015 15:38:27 +0100 Subject: [PATCH] Fix memory leak in pns_node and pns_line_placer. Fix coverity uninitialized warnings. --- pcbnew/router/pns_diff_pair.cpp | 4 +++- pcbnew/router/pns_diff_pair_placer.cpp | 18 ++++++++++++++++++ pcbnew/router/pns_dragger.cpp | 8 ++++++++ pcbnew/router/pns_line_placer.cpp | 19 ++++++++++++------- pcbnew/router/pns_node.cpp | 11 +++++++++-- pcbnew/router/pns_optimizer.cpp | 11 ++++++----- pcbnew/router/pns_tool_base.cpp | 10 ++++++++++ 7 files changed, 66 insertions(+), 15 deletions(-) diff --git a/pcbnew/router/pns_diff_pair.cpp b/pcbnew/router/pns_diff_pair.cpp index 1acc0729d8..34d25fb567 100644 --- a/pcbnew/router/pns_diff_pair.cpp +++ b/pcbnew/router/pns_diff_pair.cpp @@ -385,7 +385,6 @@ void PNS_DP_GATEWAYS::BuildFromPrimitivePair( PNS_DP_PRIMITIVE_PAIR aPair, bool p0_n = aPair.AnchorN(); shP = aPair.PrimP()->Shape(); - } else if( aPair.PrimP()->OfKind( PNS_ITEM::SEGMENT ) && aPair.PrimN()->OfKind( PNS_ITEM::SEGMENT ) ) { @@ -396,6 +395,9 @@ void PNS_DP_GATEWAYS::BuildFromPrimitivePair( PNS_DP_PRIMITIVE_PAIR aPair, bool majorDirection = ( p0_p - p0_n ).Perpendicular(); + if( shP == NULL ) + return; + switch( shP->Type() ) { case SH_RECT: diff --git a/pcbnew/router/pns_diff_pair_placer.cpp b/pcbnew/router/pns_diff_pair_placer.cpp index c7479637fb..994896eda6 100644 --- a/pcbnew/router/pns_diff_pair_placer.cpp +++ b/pcbnew/router/pns_diff_pair_placer.cpp @@ -42,11 +42,29 @@ using boost::optional; PNS_DIFF_PAIR_PLACER::PNS_DIFF_PAIR_PLACER( PNS_ROUTER* aRouter ) : PNS_PLACEMENT_ALGO ( aRouter ) { + m_state = RT_START; + m_chainedPlacement = false; m_initialDiagonal = false; m_startDiagonal = false; + m_fitOk = false; + m_netP = 0; + m_netN = 0; + m_iteration = 0; m_world = NULL; m_shove = NULL; m_currentNode = NULL; + m_lastNode = NULL; + m_placingVia = false; + m_viaDiameter = 0; + m_viaDrill = 0; + m_currentWidth = 0; + m_currentNet = 0; + m_currentLayer = 0; + m_startsOnVia = false; + m_orthoMode = false; + m_snapOnTarget = false; + m_currentEndItem = NULL; + m_currentMode = RM_MarkObstacles; m_idle = true; } diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index f369686919..9964040fb6 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -28,7 +28,15 @@ PNS_DRAGGER::PNS_DRAGGER( PNS_ROUTER* aRouter ) : PNS_ALGO_BASE( aRouter ) { m_world = NULL; + m_lastNode = NULL; + m_mode = SEGMENT; + m_draggedLine = NULL; + m_draggedVia = NULL; m_shove = NULL; + m_draggedSegmentIndex = 0; + m_dragStatus = false; + m_currentMode = RM_MarkObstacles; + m_initialVia = NULL; } diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index 9a9ff9b1c1..8afe97ab9b 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -929,7 +929,9 @@ bool PNS_LINE_PLACER::FixRoute( const VECTOR2I& aP, PNS_ITEM* aEndItem ) m_chainedPlacement = !pl.EndsWithVia(); m_splitSeg = false; initPlacement( ); - } else { + } + else + { m_idle = true; } @@ -955,7 +957,7 @@ void PNS_LINE_PLACER::removeLoops( PNS_NODE* aNode, PNS_LINE* aLatest ) if( a == b ) { - aNode->FindLineEnds( aLatest, a, b); + aNode->FindLineEnds( aLatest, a, b ); } aNode->FindLinesBetweenJoints( a, b, lines ); @@ -992,20 +994,23 @@ void PNS_LINE_PLACER::simplifyNewLine( PNS_NODE* aNode, PNS_SEGMENT* aLatest ) if( simplified.PointCount() != l->PointCount() ) { - std::auto_ptr lnew ( l->Clone() ); - aNode -> Remove( l ); + std::auto_ptr lnew( l->Clone() ); + aNode->Remove( l ); lnew->SetShape( simplified ); - aNode -> Add( lnew.get() ); + aNode->Add( lnew.get() ); } + + delete l; } void PNS_LINE_PLACER::UpdateSizes( const PNS_SIZES_SETTINGS& aSizes ) { m_sizes = aSizes; + if( !m_idle ) { - initPlacement ( m_splitSeg ); + initPlacement( m_splitSeg ); Move ( m_currentEnd, NULL ); } } @@ -1015,7 +1020,7 @@ void PNS_LINE_PLACER::updateLeadingRatLine() { PNS_LINE current = Trace(); SHAPE_LINE_CHAIN ratLine; - PNS_TOPOLOGY topo ( m_lastNode ); + PNS_TOPOLOGY topo( m_lastNode ); if( topo.LeadingRatLine( ¤t, ratLine ) ) Router()->DisplayDebugLine( ratLine, 5, 10000 ); diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index 08e7d75a1c..2a36991ec6 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -52,6 +52,7 @@ PNS_NODE::PNS_NODE() m_root = this; m_parent = NULL; m_maxClearance = 800000; // fixme: depends on how thick traces are. + m_clearanceFunctor = NULL; m_index = new PNS_INDEX; m_collisionFilter = NULL; @@ -179,6 +180,8 @@ struct PNS_NODE::OBSTACLE_VISITOR int m_extraClearance; OBSTACLE_VISITOR( PNS_NODE::OBSTACLES& aTab, const PNS_ITEM* aItem, int aKindMask ) : + m_node( NULL ), + m_override( NULL ), m_tab( aTab ), m_item( aItem ), m_kindMask( aKindMask ), @@ -517,11 +520,15 @@ void PNS_NODE::addLine( PNS_LINE* aLine, bool aAllowRedundant ) PNS_SEGMENT* pseg = new PNS_SEGMENT( *aLine, s ); PNS_SEGMENT* psegR = NULL; - if ( !aAllowRedundant ) - psegR = findRedundantSegment( pseg ); + if( !aAllowRedundant ) + psegR = findRedundantSegment( pseg ); if( psegR ) + { aLine->LinkSegment( psegR ); + + delete pseg; + } else { pseg->SetOwner( this ); diff --git a/pcbnew/router/pns_optimizer.cpp b/pcbnew/router/pns_optimizer.cpp index 0cebcd86ab..5558d8de72 100644 --- a/pcbnew/router/pns_optimizer.cpp +++ b/pcbnew/router/pns_optimizer.cpp @@ -119,16 +119,17 @@ bool PNS_COST_ESTIMATOR::IsBetter( PNS_COST_ESTIMATOR& aOther, * Optimizer **/ PNS_OPTIMIZER::PNS_OPTIMIZER( PNS_NODE* aWorld ) : - m_world( aWorld ), m_collisionKindMask( PNS_ITEM::ANY ), m_effortLevel( MERGE_SEGMENTS ) + m_world( aWorld ), + m_collisionKindMask( PNS_ITEM::ANY ), + m_effortLevel( MERGE_SEGMENTS ), + m_keepPostures( false ), + m_restrictAreaActive( false ) { - // m_cache = new SHAPE_INDEX_LIST(); - m_restrictAreaActive = false; } PNS_OPTIMIZER::~PNS_OPTIMIZER() { - // delete m_cache; } @@ -188,7 +189,7 @@ void PNS_OPTIMIZER::removeCachedSegments( PNS_LINE* aLine, int aStartVertex, int PNS_SEGMENT* s = (*segs)[i]; m_cacheTags.erase( s ); m_cache.Remove( s ); - } // *cacheRemove( (*segs)[i] ); + } } diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 9491d81a2c..8ba2d30a45 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -64,6 +64,16 @@ PNS_TOOL_BASE::PNS_TOOL_BASE( const std::string& aToolName ) : TOOL_INTERACTIVE( aToolName ) { m_router = NULL; + m_startItem = NULL; + m_startLayer = 0; + + m_endItem = NULL; + + m_needsSync = false; + + m_frame = NULL; + m_ctls = NULL; + m_board = NULL; }