Skip to content
Permalink
Browse files

Fix some leaks in geometry tests (valgrind noise)

  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent 9526d48 commit 6f5d9c94a62f7a05a8495215683443f1c5e418d1
@@ -55,7 +55,7 @@ QgsCurvePolygon::QgsCurvePolygon( const QgsCurvePolygon &p )
mWkbType = p.mWkbType;
if ( p.mExteriorRing )
{
mExteriorRing = static_cast<QgsCurve *>( p.mExteriorRing->clone() );
mExteriorRing.reset( static_cast<QgsCurve *>( p.mExteriorRing->clone() ) );
}

for ( const QgsCurve *ring : p.mInteriorRings )
@@ -72,7 +72,7 @@ QgsCurvePolygon &QgsCurvePolygon::operator=( const QgsCurvePolygon &p )
QgsSurface::operator=( p );
if ( p.mExteriorRing )
{
mExteriorRing = static_cast<QgsCurve *>( p.mExteriorRing->clone() );
mExteriorRing.reset( static_cast<QgsCurve *>( p.mExteriorRing->clone() ) );
}

for ( const QgsCurve *ring : p.mInteriorRings )
@@ -129,8 +129,7 @@ QgsCurvePolygon *QgsCurvePolygon::clone() const
void QgsCurvePolygon::clear()
{
mWkbType = QgsWkbTypes::CurvePolygon;
delete mExteriorRing;
mExteriorRing = nullptr;
mExteriorRing.reset();
qDeleteAll( mInteriorRings );
mInteriorRings.clear();
clearCache();
@@ -154,23 +153,23 @@ bool QgsCurvePolygon::fromWkb( QgsConstWkbPtr &wkbPtr )

int nRings;
wkbPtr >> nRings;
QgsCurve *currentCurve = nullptr;
std::unique_ptr< QgsCurve > currentCurve;
for ( int i = 0; i < nRings; ++i )
{
QgsWkbTypes::Type curveType = wkbPtr.readHeader();
wkbPtr -= 1 + sizeof( int );
QgsWkbTypes::Type flatCurveType = QgsWkbTypes::flatType( curveType );
if ( flatCurveType == QgsWkbTypes::LineString )
{
currentCurve = new QgsLineString();
currentCurve.reset( new QgsLineString() );
}
else if ( flatCurveType == QgsWkbTypes::CircularString )
{
currentCurve = new QgsCircularString();
currentCurve.reset( new QgsCircularString() );
}
else if ( flatCurveType == QgsWkbTypes::CompoundCurve )
{
currentCurve = new QgsCompoundCurve();
currentCurve.reset( new QgsCompoundCurve() );
}
else
{
@@ -179,11 +178,11 @@ bool QgsCurvePolygon::fromWkb( QgsConstWkbPtr &wkbPtr )
currentCurve->fromWkb( wkbPtr ); // also updates wkbPtr
if ( i == 0 )
{
mExteriorRing = currentCurve;
mExteriorRing = std::move( currentCurve );
}
else
{
mInteriorRings.append( currentCurve );
mInteriorRings.append( currentCurve.release() );
}
}

@@ -233,8 +232,7 @@ bool QgsCurvePolygon::fromWkt( const QString &wkt )
return false;
}

mExteriorRing = mInteriorRings.at( 0 );
mInteriorRings.removeFirst();
mExteriorRing.reset( mInteriorRings.takeFirst() );

//scan through rings and check if dimensionality of rings is different to CurvePolygon.
//if so, update the type dimensionality of the CurvePolygon to match
@@ -305,7 +303,7 @@ QString QgsCurvePolygon::asWkt( int precision ) const
if ( mExteriorRing )
{
QString childWkt = mExteriorRing->asWkt( precision );
if ( qgsgeometry_cast<QgsLineString *>( mExteriorRing ) )
if ( qgsgeometry_cast<QgsLineString *>( mExteriorRing.get() ) )
{
// Type names of linear geometries are omitted
childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
@@ -518,7 +516,7 @@ int QgsCurvePolygon::numInteriorRings() const

const QgsCurve *QgsCurvePolygon::exteriorRing() const
{
return mExteriorRing;
return mExteriorRing.get();
}

const QgsCurve *QgsCurvePolygon::interiorRing( int i ) const
@@ -536,8 +534,7 @@ void QgsCurvePolygon::setExteriorRing( QgsCurve *ring )
{
return;
}
delete mExteriorRing;
mExteriorRing = ring;
mExteriorRing.reset( ring );

//set proper wkb type
if ( QgsWkbTypes::flatType( wkbType() ) == QgsWkbTypes::Polygon )
@@ -737,7 +734,7 @@ double QgsCurvePolygon::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt,
return -1;
}
QList<QgsCurve *> segmentList;
segmentList.append( mExteriorRing );
segmentList.append( mExteriorRing.get() );
segmentList.append( mInteriorRings );
return QgsGeometryUtils::closestSegmentFromComponents( segmentList, QgsGeometryUtils::Ring, pt, segmentPt, vertexAfter, leftOf, epsilon );
}
@@ -761,7 +758,7 @@ bool QgsCurvePolygon::nextVertex( QgsVertexId &vId, QgsPoint &vertex ) const
}
else
{
QgsCurve *ring = vId.ring == 0 ? mExteriorRing : mInteriorRings[vId.ring - 1];
QgsCurve *ring = vId.ring == 0 ? mExteriorRing.get() : mInteriorRings[vId.ring - 1];

if ( ring->nextVertex( vId, vertex ) )
{
@@ -785,7 +782,7 @@ bool QgsCurvePolygon::insertVertex( QgsVertexId vId, const QgsPoint &vertex )
return false;
}

QgsCurve *ring = vId.ring == 0 ? mExteriorRing : mInteriorRings.at( vId.ring - 1 );
QgsCurve *ring = vId.ring == 0 ? mExteriorRing.get() : mInteriorRings.at( vId.ring - 1 );
int n = ring->numPoints();
bool success = ring->insertVertex( QgsVertexId( 0, 0, vId.vertex ), vertex );
if ( !success )
@@ -811,7 +808,7 @@ bool QgsCurvePolygon::moveVertex( QgsVertexId vId, const QgsPoint &newPos )
return false;
}

QgsCurve *ring = vId.ring == 0 ? mExteriorRing : mInteriorRings.at( vId.ring - 1 );
QgsCurve *ring = vId.ring == 0 ? mExteriorRing.get() : mInteriorRings.at( vId.ring - 1 );
int n = ring->numPoints();
bool success = ring->moveVertex( vId, newPos );
if ( success )
@@ -833,18 +830,17 @@ bool QgsCurvePolygon::deleteVertex( QgsVertexId vId )
return false;
}

QgsCurve *ring = vId.ring == 0 ? mExteriorRing : mInteriorRings.at( vId.ring - 1 );
QgsCurve *ring = vId.ring == 0 ? mExteriorRing.get() : mInteriorRings.at( vId.ring - 1 );
int n = ring->numPoints();
if ( n <= 4 )
{
//no points will be left in ring, so remove whole ring
if ( vId.ring == 0 )
{
delete mExteriorRing;
mExteriorRing = nullptr;
mExteriorRing.reset();
if ( !mInteriorRings.isEmpty() )
{
mExteriorRing = mInteriorRings.takeFirst();
mExteriorRing.reset( mInteriorRings.takeFirst() );
}
}
else
@@ -901,7 +897,7 @@ double QgsCurvePolygon::vertexAngle( QgsVertexId vertex ) const
return false;
}

QgsCurve *ring = vertex.ring == 0 ? mExteriorRing : mInteriorRings[vertex.ring - 1];
QgsCurve *ring = vertex.ring == 0 ? mExteriorRing.get() : mInteriorRings[vertex.ring - 1];
return ring->vertexAngle( vertex );
}

@@ -21,6 +21,7 @@
#include "qgis_core.h"
#include "qgis.h"
#include "qgssurface.h"
#include <memory>

class QgsPolygonV2;

@@ -167,7 +168,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
#endif
protected:

QgsCurve *mExteriorRing = nullptr;
std::unique_ptr< QgsCurve > mExteriorRing;
QList<QgsCurve *> mInteriorRings;

QgsRectangle calculateBoundingBox() const override;
@@ -83,7 +83,7 @@ bool QgsPolygonV2::fromWkb( QgsConstWkbPtr &wkbPtr )
wkbPtr >> nRings;
for ( int i = 0; i < nRings; ++i )
{
QgsLineString *line = new QgsLineString();
std::unique_ptr< QgsLineString > line( new QgsLineString() );
line->fromWkbPoints( ringType, wkbPtr );
/*if ( !line->isRing() )
{
@@ -92,11 +92,11 @@ bool QgsPolygonV2::fromWkb( QgsConstWkbPtr &wkbPtr )

if ( !mExteriorRing )
{
mExteriorRing = line;
mExteriorRing = std::move( line );
}
else
{
mInteriorRings.append( line );
mInteriorRings.append( line.release() );
}
}

@@ -176,7 +176,6 @@ void QgsPolygonV2::setExteriorRing( QgsCurve *ring )
{
return;
}
delete mExteriorRing;

if ( ring->hasCurvedSegments() )
{
@@ -192,7 +191,7 @@ void QgsPolygonV2::setExteriorRing( QgsCurve *ring )
lineString->close();
}

mExteriorRing = ring;
mExteriorRing.reset( ring );

//set proper wkb type
setZMTypeFromSubGeometry( ring, QgsWkbTypes::Polygon );
@@ -241,7 +240,7 @@ double QgsPolygonV2::pointDistanceToBoundary( double x, double y ) const
int numRings = mInteriorRings.size() + 1;
for ( int ringIndex = 0; ringIndex < numRings; ++ringIndex )
{
const QgsLineString *ring = static_cast< const QgsLineString * >( ringIndex == 0 ? mExteriorRing : mInteriorRings.at( ringIndex - 1 ) );
const QgsLineString *ring = static_cast< const QgsLineString * >( ringIndex == 0 ? mExteriorRing.get() : mInteriorRings.at( ringIndex - 1 ) );

int len = ring->numPoints() - 1; //assume closed
for ( int i = 0, j = len - 1; i < len; j = i++ )
@@ -166,7 +166,7 @@ bool QgsTriangle::fromWkb( QgsConstWkbPtr &wkbPtr )
line->fromWkbPoints( ringType, wkbPtr );
if ( !mExteriorRing )
{
mExteriorRing = line;
mExteriorRing.reset( line );
}

return true;
@@ -211,8 +211,7 @@ bool QgsTriangle::fromWkt( const QString &wkt )
clear();
return false;
}
mExteriorRing = mInteriorRings.at( 0 );
mInteriorRings.removeFirst();
mExteriorRing.reset( mInteriorRings.takeFirst() );

//scan through rings and check if dimensionality of rings is different to CurvePolygon.
//if so, update the type dimensionality of the CurvePolygon to match
@@ -246,7 +245,7 @@ QgsCurvePolygon *QgsTriangle::toCurveType() const

void QgsTriangle::addInteriorRing( QgsCurve *ring )
{
Q_UNUSED( ring );
delete ring;
}

bool QgsTriangle::deleteVertex( QgsVertexId position )
@@ -283,14 +282,13 @@ bool QgsTriangle::moveVertex( QgsVertexId vId, const QgsPoint &newPos )
return false;
}

QgsCurve *ring = mExteriorRing;
int n = ring->numPoints();
bool success = ring->moveVertex( vId, newPos );
int n = mExteriorRing->numPoints();
bool success = mExteriorRing->moveVertex( vId, newPos );
if ( success )
{
// If first or last vertex is moved, also move the last/first vertex
if ( vId.vertex == 0 )
ring->moveVertex( QgsVertexId( vId.part, vId.ring, n - 1 ), newPos );
mExteriorRing->moveVertex( QgsVertexId( vId.part, vId.ring, n - 1 ), newPos );
clearCache();
}
return success;
@@ -313,19 +311,22 @@ void QgsTriangle::setExteriorRing( QgsCurve *ring )

if ( ( ring->numPoints() > 4 ) || ( ring->numPoints() < 3 ) )
{
delete ring;
return;
}
else if ( ring->numPoints() == 4 )
{
if ( !ring->isClosed() )
{
delete ring;
return;
}
}
else if ( ring->numPoints() == 3 )
{
if ( ring->isClosed() )
{
delete ring;
return;
}
QgsLineString *lineString = static_cast< QgsLineString *>( ring );
@@ -338,12 +339,11 @@ void QgsTriangle::setExteriorRing( QgsCurve *ring )

if ( !validateGeom( ring->vertexAt( QgsVertexId( 0, 0, 0 ) ), ring->vertexAt( QgsVertexId( 0, 0, 1 ) ), ring->vertexAt( QgsVertexId( 0, 0, 2 ) ) ) )
{
delete ring;
return;
}

delete mExteriorRing;

mExteriorRing = ring;
mExteriorRing.reset( ring );

//set proper wkb type
setZMTypeFromSubGeometry( ring, QgsWkbTypes::Triangle );

0 comments on commit 6f5d9c9

Please sign in to comment.
You can’t perform that action at this time.