kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #21199
[PATCH] memory leak in meander placer [was: RC2]
On 07.11.2015 21:41, Wayne Stambaugh wrote:
>>>> And speaking of pns, there is still CID 106401 where
>>>> PNS_MEANDERED_LINE::MeanderSegment can memory leak.
Here's a patch for that.
Cheers,
T.
>From cd30ed5522dcced484ad6b0a80a0c35e1171c957 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= <tomasz.wlostowski@xxxxxxx>
Date: Mon, 9 Nov 2015 10:19:31 +0100
Subject: [PATCH] router: fixed memory leak in the meander placer
---
pcbnew/router/pns_meander.cpp | 31 ++++++++++++++++---------------
pcbnew/router/pns_meander.h | 5 +++++
2 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/pcbnew/router/pns_meander.cpp b/pcbnew/router/pns_meander.cpp
index 5bca9bb..6739401 100644
--- a/pcbnew/router/pns_meander.cpp
+++ b/pcbnew/router/pns_meander.cpp
@@ -61,11 +61,12 @@ void PNS_MEANDERED_LINE::MeanderSegment( const SEG& aBase, int aBaseIndex )
do
{
- PNS_MEANDER_SHAPE* m = new PNS_MEANDER_SHAPE( m_placer, m_width, m_dual );
- m->SetBaselineOffset( m_baselineOffset );
- m->SetBaseIndex( aBaseIndex );
+ PNS_MEANDER_SHAPE m( m_placer, m_width, m_dual );
- double thr = (double) m->spacing();
+ m.SetBaselineOffset( m_baselineOffset );
+ m.SetBaseIndex( aBaseIndex );
+
+ double thr = (double) m.spacing();
bool fail = false;
double remaining = base_len - ( m_last - aBase.A ).EuclideanNorm();
@@ -79,10 +80,10 @@ void PNS_MEANDERED_LINE::MeanderSegment( const SEG& aBase, int aBaseIndex )
{
for( int i = 0; i < 2; i++ )
{
- if ( m->Fit( MT_CHECK_START, aBase, m_last, i ) )
+ if ( m.Fit( MT_CHECK_START, aBase, m_last, i ) )
{
turning = true;
- AddMeander( m );
+ AddMeander( new PNS_MEANDER_SHAPE( m ) );
side = !i;
started = true;
break;
@@ -95,9 +96,9 @@ void PNS_MEANDERED_LINE::MeanderSegment( const SEG& aBase, int aBaseIndex )
for( int i = 0; i < 2; i++ )
{
- if ( m->Fit ( MT_SINGLE, aBase, m_last, i ) )
+ if ( m.Fit ( MT_SINGLE, aBase, m_last, i ) )
{
- AddMeander( m );
+ AddMeander( new PNS_MEANDER_SHAPE( m ) );
fail = false;
started = false;
side = !i;
@@ -106,17 +107,17 @@ void PNS_MEANDERED_LINE::MeanderSegment( const SEG& aBase, int aBaseIndex )
}
}
} else {
- bool rv = m->Fit( MT_CHECK_FINISH, aBase, m_last, side );
+ bool rv = m.Fit( MT_CHECK_FINISH, aBase, m_last, side );
if( rv )
{
- m->Fit( MT_TURN, aBase, m_last, side );
- AddMeander( m );
+ m.Fit( MT_TURN, aBase, m_last, side );
+ AddMeander( new PNS_MEANDER_SHAPE( m ) );
started = true;
} else {
- m->Fit( MT_FINISH, aBase, m_last, side );
+ m.Fit( MT_FINISH, aBase, m_last, side );
started = false;
- AddMeander( m );
+ AddMeander( new PNS_MEANDER_SHAPE( m ) );
turning = false;
}
@@ -124,9 +125,9 @@ void PNS_MEANDERED_LINE::MeanderSegment( const SEG& aBase, int aBaseIndex )
}
} else if( started )
{
- bool rv = m->Fit( MT_FINISH, aBase, m_last, side );
+ bool rv = m.Fit( MT_FINISH, aBase, m_last, side );
if( rv )
- AddMeander( m );
+ AddMeander( new PNS_MEANDER_SHAPE( m ) );
break;
diff --git a/pcbnew/router/pns_meander.h b/pcbnew/router/pns_meander.h
index 88fb2cc..5d1ae51 100644
--- a/pcbnew/router/pns_meander.h
+++ b/pcbnew/router/pns_meander.h
@@ -416,6 +416,11 @@ public:
m_baselineOffset = 0;
}
+ ~PNS_MEANDERED_LINE()
+ {
+ Clear();
+ }
+
/**
* Function AddCorner()
*
--
1.9.1
Follow ups
References
-
RC2
From: Wayne Stambaugh, 2015-11-06
-
Re: RC2
From: Mark Roszko, 2015-11-06
-
Re: RC2
From: Wayne Stambaugh, 2015-11-06
-
Re: RC2
From: jp charras, 2015-11-07
-
Re: RC2
From: Wayne Stambaugh, 2015-11-07