Skip to content

Commit

Permalink
Fix a bunch of memory leaks
Browse files Browse the repository at this point in the history
...thanks Coverity, thoverity.
  • Loading branch information
nyalldawson committed Feb 5, 2015
1 parent f6d6c69 commit 73b9569
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/analysis/vector/qgstransectsample.cpp
Expand Up @@ -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 )
{
Expand All @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsgeometry.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsgml.cpp
Expand Up @@ -492,6 +492,7 @@ void QgsGml::endElement( const XML_Char* el )
}
else
{
delete[] wkb;
QgsDebugMsg( "no wkb fragments" );
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsogcutils.cpp
Expand Up @@ -1653,6 +1653,7 @@ QgsExpression::NodeFunction* QgsOgcUtils::nodeSpatialOperatorFromOgcFilter( QDom
else
{
errorMessage = QString( "No OGC Geometry found" );
delete gml2Args;
return NULL;
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgscubicrasterresampler.cpp
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/core/raster/qgsrasterresamplefilter.cpp
Expand Up @@ -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 );
}

Expand Down
1 change: 1 addition & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -2974,6 +2974,7 @@ QgsPointPatternFillSymbolLayer::QgsPointPatternFillSymbolLayer(): QgsImageFillSy

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

void QgsPointPatternFillSymbolLayer::setOutputUnit( QgsSymbolV2::OutputUnit unit )
Expand Down
15 changes: 13 additions & 2 deletions src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -124,6 +134,7 @@ bool QgsVectorFieldSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
{
if ( symbol->type() == QgsSymbolV2::Line )
{
delete mLineSymbol;
mLineSymbol = static_cast<QgsLineSymbolV2*>( symbol );
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/roadgraph/shortestpathwidget.cpp
Expand Up @@ -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;
}
Expand Down
39 changes: 25 additions & 14 deletions src/plugins/topology/topolTest.cpp
Expand Up @@ -314,6 +314,7 @@ ErrorList topolTest::checkDanglingLines( double tolerance, QgsVectorLayer* layer
{
if ( canvasExtentPoly->disjoint( conflictGeom ) )
{
delete conflictGeom;
continue;
}
}
Expand All @@ -335,7 +336,7 @@ ErrorList topolTest::checkDanglingLines( double tolerance, QgsVectorLayer* layer

}
}

delete canvasExtentPoly;
return errorList;
}

Expand All @@ -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()];

Expand All @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -564,7 +564,7 @@ ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, Qg
}

}

delete canvasExtentPoly;
}

return errorList;
Expand Down Expand Up @@ -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-";
Expand Down Expand Up @@ -718,6 +720,7 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
errorList << err;
}

delete canvasExtentPoly;
return errorList;
}

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

}
}

delete canvasExtentPoly;
return errorList;
}

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

delete canvasExtentPoly;
return errorList;
}

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

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 )
Expand Down Expand Up @@ -1359,6 +1366,9 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
}

}
delete startPoint;
delete endPoint;

if ( !touched )
{
QgsGeometry* conflictGeom = new QgsGeometry( *g1 );
Expand All @@ -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 )
Expand Down Expand Up @@ -1457,8 +1467,9 @@ ErrorList topolTest::checkPointInPolygon( double tolerance, QgsVectorLayer *laye
errorList << err;
}
}
return errorList;

delete canvasExtentPoly;
return errorList;
}


Expand Down
6 changes: 6 additions & 0 deletions src/providers/gpx/qgsgpxfeatureiterator.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
8 changes: 6 additions & 2 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/src/gui/testqgsrubberband.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit 73b9569

Please sign in to comment.