← Back to team overview

kicad-developers team mailing list archive

[PATCH] fix 2x memory leak and misc field warnings in PNS stuff

 

Fixes 1 leak in pns_line_placer and 1 leak in pns_node.
Assorted field intialization.

Based on coverity.
From 987e65fdcf962f925fc1678b425d13173ae4b3a8 Mon Sep 17 00:00:00 2001
From: Mark Roszko <mark.roszko@xxxxxxxxx>
Date: Mon, 9 Mar 2015 23:21:07 -0400
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      |  2 ++
 pcbnew/router/pns_node.cpp             |  7 +++++++
 pcbnew/router/pns_optimizer.cpp        | 11 ++++++-----
 pcbnew/router/pns_tool_base.cpp        | 10 ++++++++++
 7 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/pcbnew/router/pns_diff_pair.cpp b/pcbnew/router/pns_diff_pair.cpp
index 1acc072..34d25fb 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 c747963..994896e 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 f369686..9964040 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 9a9ff9b..45c4cfd 100644
--- a/pcbnew/router/pns_line_placer.cpp
+++ b/pcbnew/router/pns_line_placer.cpp
@@ -997,6 +997,8 @@ void PNS_LINE_PLACER::simplifyNewLine( PNS_NODE* aNode, PNS_SEGMENT* aLatest )
         lnew->SetShape( simplified );
         aNode -> Add( lnew.get() );
     }
+
+    delete l;
 }
 
 
diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp
index 08e7d75..2cb5b22 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 ),
@@ -521,7 +524,11 @@ void PNS_NODE::addLine( PNS_LINE* aLine, bool 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 0cebcd8..5558d8d 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<PNS_ITEM*>();
-    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 9491d81..8ba2d30 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;
 }
 
 
-- 
1.9.1


Follow ups