Skip to content
Permalink
Browse files

Fix a bunch of memory leaks

...thanks Coverity, thoverity.
  • Loading branch information
nyalldawson committed Feb 5, 2015
1 parent f6d6c69 commit 73b95693869641d776c2ac25c68daa45562b3f34
@@ -595,6 +595,7 @@ QgsGeometry* QgsTransectSample::clipBufferLine( QgsGeometry* stratumGeom, QgsGeo
bufferLine = QgsGeometry::fromMultiPolyline( mpl );
}
bufferLineClipped = bufferLine->intersection( stratumGeom );
delete bufferLine;

if ( bufferLineClipped && bufferLineClipped->type() == QGis::Line )
{
@@ -619,11 +620,13 @@ QgsGeometry* QgsTransectSample::clipBufferLine( QgsGeometry* stratumGeom, QgsGeo

if ( bufferLineClippedIntersectsStratum )
{
delete clipBaselineBuffer;
return bufferLineClipped;
}
}

delete bufferLineClipped; delete clipBaselineBuffer; delete bufferLine;
delete bufferLineClipped;
delete clipBaselineBuffer;
currentBufferDist /= 2;
}

@@ -4661,7 +4661,9 @@ GEOSGeometry* QgsGeometry::linePointDifference( GEOSGeometry* GEOSsplitPoint )
else
return 0;

QgsPoint splitPoint = fromGeosGeom( GEOSsplitPoint )->asPoint();
QgsGeometry* geosPoint = fromGeosGeom( GEOSsplitPoint );
QgsPoint splitPoint = geosPoint->asPoint();
delete geosPoint;

QgsMultiPolyline lines;
QgsPolyline line;
@@ -4689,9 +4691,9 @@ GEOSGeometry* QgsGeometry::linePointDifference( GEOSGeometry* GEOSsplitPoint )
}
QgsGeometry* splitLines = fromMultiPolyline( lines );
GEOSGeometry* splitGeom = GEOSGeom_clone_r( geosinit.ctxt, splitLines->asGeos() );
delete splitLines;

return splitGeom;

}

int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry*>& newGeometries )
@@ -492,6 +492,7 @@ void QgsGml::endElement( const XML_Char* el )
}
else
{
delete[] wkb;
QgsDebugMsg( "no wkb fragments" );
}
}
@@ -1653,6 +1653,7 @@ QgsExpression::NodeFunction* QgsOgcUtils::nodeSpatialOperatorFromOgcFilter( QDom
else
{
errorMessage = QString( "No OGC Geometry found" );
delete gml2Args;
return NULL;
}

@@ -263,12 +263,15 @@ void QgsCubicRasterResampler::resample( const QImage& srcImage, QImage& dstImage
delete[] redMatrix;
delete[] greenMatrix;
delete[] blueMatrix;
delete[] alphaMatrix;
delete[] xDerivativeMatrixRed;
delete[] xDerivativeMatrixGreen;
delete[] xDerivativeMatrixBlue;
delete[] xDerivativeMatrixAlpha;
delete[] yDerivativeMatrixRed;
delete[] yDerivativeMatrixGreen;
delete[] yDerivativeMatrixBlue;
delete[] yDerivativeMatrixAlpha;
}

void QgsCubicRasterResampler::xDerivativeMatrix( int nCols, int nRows, double* matrix, const int* colorMatrix )
@@ -167,6 +167,7 @@ QgsRasterBlock * QgsRasterResampleFilter::block( int bandNo, QgsRectangle const
if ((( oversampling < 1.0 || qgsDoubleNear( oversampling, 1.0 ) ) && !mZoomedInResampler ) || ( oversampling > 1.0 && !mZoomedOutResampler ) )
{
QgsDebugMsg( "No oversampling." );
delete outputBlock;
return mInput->block( bandNumber, extent, width, height );
}

@@ -2974,6 +2974,7 @@ QgsPointPatternFillSymbolLayer::QgsPointPatternFillSymbolLayer(): QgsImageFillSy

QgsPointPatternFillSymbolLayer::~QgsPointPatternFillSymbolLayer()
{
delete mMarkerSymbol;
}

void QgsPointPatternFillSymbolLayer::setOutputUnit( QgsSymbolV2::OutputUnit unit )
@@ -18,14 +18,24 @@
#include "qgsvectorfieldsymbollayer.h"
#include "qgsvectorlayer.h"

QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer(): mXAttribute( "" ), mYAttribute( "" ), mDistanceUnit( QgsSymbolV2::MM ), mScale( 1.0 ),
mVectorFieldType( Cartesian ), mAngleOrientation( ClockwiseFromNorth ), mAngleUnits( Degrees ), mXIndex( -1 ), mYIndex( -1 )
QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer()
: mXAttribute( "" )
, mYAttribute( "" )
, mDistanceUnit( QgsSymbolV2::MM )
, mScale( 1.0 )
, mVectorFieldType( Cartesian )
, mAngleOrientation( ClockwiseFromNorth )
, mAngleUnits( Degrees )
, mLineSymbol( 0 )
, mXIndex( -1 )
, mYIndex( -1 )
{
setSubSymbol( new QgsLineSymbolV2() );
}

QgsVectorFieldSymbolLayer::~QgsVectorFieldSymbolLayer()
{
delete mLineSymbol;
}

void QgsVectorFieldSymbolLayer::setOutputUnit( QgsSymbolV2::OutputUnit unit )
@@ -124,6 +134,7 @@ bool QgsVectorFieldSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
{
if ( symbol->type() == QgsSymbolV2::Line )
{
delete mLineSymbol;
mLineSymbol = static_cast<QgsLineSymbolV2*>( symbol );
return true;
}
@@ -90,18 +90,19 @@ void dxf2shpConverterGui::on_buttonBox_accepted()
convtexts );

QgsDebugMsg( QString( "Finished getting insertions. Count: %1" ).arg( insertRetr->countInserts ) );
delete dxf_inserts;

DL_Dxf *dxf_Main = new DL_Dxf();

if ( !dxf_Main->in( inf.toStdString(), parser ) )
{
// if file open failed
delete dxf_Main;
QgsDebugMsg( "Aborting: The input file could not be opened." );
return;
}

delete insertRetr;
delete dxf_inserts;
delete dxf_Main;

parser->print_shpObjects();
@@ -305,6 +305,7 @@ QgsGraph* RgShortestPathWidget::getPath( QgsPoint& p1, QgsPoint& p2 )

if ( shortestpathTree->findVertex( p2 ) == -1 )
{
delete shortestpathTree;
QMessageBox::critical( this, tr( "Path not found" ), tr( "Path not found" ) );
return NULL;
}
@@ -314,6 +314,7 @@ ErrorList topolTest::checkDanglingLines( double tolerance, QgsVectorLayer* layer
{
if ( canvasExtentPoly->disjoint( conflictGeom ) )
{
delete conflictGeom;
continue;
}
}
@@ -335,7 +336,7 @@ ErrorList topolTest::checkDanglingLines( double tolerance, QgsVectorLayer* layer

}
}

delete canvasExtentPoly;
return errorList;
}

@@ -347,7 +348,7 @@ ErrorList topolTest::checkDuplicates( double tolerance, QgsVectorLayer *layer1,
int i = 0;
ErrorList errorList;

QList<QgsFeatureId>* duplicateIds = new QList<QgsFeatureId>();
QList<QgsFeatureId> duplicateIds;

QgsSpatialIndex* index = mLayerIndexes[layer1->id()];

@@ -363,7 +364,7 @@ ErrorList topolTest::checkDuplicates( double tolerance, QgsVectorLayer *layer1,

QgsFeatureId currentId = it->feature.id();

if ( duplicateIds->contains( currentId ) )
if ( duplicateIds.contains( currentId ) )
{
//is already a duplicate geometry..skip..
continue;
@@ -406,7 +407,7 @@ ErrorList topolTest::checkDuplicates( double tolerance, QgsVectorLayer *layer1,
if ( g1->equals( g2 ) )
{
duplicate = true;
duplicateIds->append( mFeatureMap2[*cit].feature.id() );
duplicateIds.append( mFeatureMap2[*cit].feature.id() );
}

if ( duplicate )
@@ -437,9 +438,8 @@ ErrorList topolTest::checkDuplicates( double tolerance, QgsVectorLayer *layer1,
}

}

delete canvasExtentPoly;
return errorList;

}

ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, QgsVectorLayer *layer2, bool isExtent )
@@ -564,7 +564,7 @@ ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, Qg
}

}

delete canvasExtentPoly;
}

return errorList;
@@ -678,10 +678,12 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
QString extentWkt = test.boundingBox().asWktPolygon();
QgsGeometry* extentGeom = QgsGeometry::fromWkt( extentWkt );
QgsGeometry* bufferExtent = extentGeom->buffer( 2, 3 );
delete extentGeom;

//qDebug() << "extent wkt - " << bufferExtent->exportToWkt();

QgsGeometry* diffGeoms = bufferExtent->difference( &test );
delete bufferExtent;
if ( !diffGeoms )
{
qDebug() << "difference result 0-";
@@ -718,6 +720,7 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
errorList << err;
}

delete canvasExtentPoly;
return errorList;
}

@@ -810,6 +813,7 @@ ErrorList topolTest::checkPseudos( double tolerance, QgsVectorLayer *layer1, Qgs
{
if ( canvasExtentPoly->disjoint( conflictGeom ) )
{
delete conflictGeom;
continue;
}
}
@@ -831,7 +835,7 @@ ErrorList topolTest::checkPseudos( double tolerance, QgsVectorLayer *layer1, Qgs

}
}

delete canvasExtentPoly;
return errorList;
}

@@ -962,7 +966,7 @@ ErrorList topolTest::checkPointCoveredBySegment( double tolerance, QgsVectorLaye
errorList << err;
}
}

delete canvasExtentPoly;
return errorList;
}

@@ -1205,6 +1209,7 @@ ErrorList topolTest::checkOverlapWithLayer( double tolerance, QgsVectorLayer* la
}
}
}
delete canvasExtentPoly;
return errorList;
}

@@ -1257,10 +1262,12 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
}
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2->asPolyline().first() );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g2->asPolyline().last() );
touched = g1->intersects( startPoint ) || g1->intersects( endPoint );
delete startPoint;
delete endPoint;

if ( g1->intersects( startPoint ) || g1->intersects( endPoint ) )
if ( touched )
{
touched = true;
break;
}
}
@@ -1283,8 +1290,8 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
errorList << err;
}
}
delete canvasExtentPoly;
return errorList;

}

ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorLayer *layer1, QgsVectorLayer *layer2, bool isExtent )
@@ -1359,6 +1366,9 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
}

}
delete startPoint;
delete endPoint;

if ( !touched )
{
QgsGeometry* conflictGeom = new QgsGeometry( *g1 );
@@ -1383,8 +1393,8 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
errorList << err;
}
}
delete canvasExtentPoly;
return errorList;

}

ErrorList topolTest::checkPointInPolygon( double tolerance, QgsVectorLayer *layer1, QgsVectorLayer *layer2, bool isExtent )
@@ -1457,8 +1467,9 @@ ErrorList topolTest::checkPointInPolygon( double tolerance, QgsVectorLayer *laye
errorList << err;
}
}
return errorList;

delete canvasExtentPoly;
return errorList;
}


@@ -211,7 +211,10 @@ bool QgsGPXFeatureIterator::readRoute( const QgsRoute& rte, QgsFeature& feature
const QgsRectangle& rect = mRequest.filterRect();
if (( rte.xMax < rect.xMinimum() ) || ( rte.xMin > rect.xMaximum() ) ||
( rte.yMax < rect.yMinimum() ) || ( rte.yMin > rect.yMaximum() ) )
{
delete theGeometry;
return false;
}

if ( !theGeometry->intersects( rect ) ) //use geos for precise intersection test
{
@@ -250,7 +253,10 @@ bool QgsGPXFeatureIterator::readTrack( const QgsTrack& trk, QgsFeature& feature
const QgsRectangle& rect = mRequest.filterRect();
if (( trk.xMax < rect.xMinimum() ) || ( trk.xMin > rect.xMaximum() ) ||
( trk.yMax < rect.yMinimum() ) || ( trk.yMin > rect.yMaximum() ) )
{
delete theGeometry;
return false;
}

if ( !theGeometry->intersects( rect ) ) //use geos for precise intersection test
{
@@ -867,8 +867,12 @@ class TestQgsExpression: public QObject
QgsGeometry* tPolygon = QgsGeometry::fromPolygon( polygon );
tPolygon->transform( t );

QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + QgsGeometry::fromPolyline( line )->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tLine << false;
QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + QgsGeometry::fromPolygon( polygon )->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tPolygon << false;
QgsGeometry* oLine = QgsGeometry::fromPolyline( line );
QgsGeometry* oPolygon = QgsGeometry::fromPolygon( polygon );
QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + oLine->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tLine << false;
QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + oPolygon->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tPolygon << false;
delete oLine;
delete oPolygon;
}

void eval_geometry_access_transform()
@@ -97,6 +97,9 @@ void TestQgsRubberband::testAddSingleMultiGeometries()
mRubberband->addGeometry( geomSinglePart, mPolygonLayer );
mRubberband->addGeometry( geomMultiPart, mPolygonLayer );
QVERIFY( mRubberband->numberOfVertices() == 15 );

delete geomSinglePart;
delete geomMultiPart;
}

QTEST_MAIN( TestQgsRubberband )

0 comments on commit 73b9569

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