Skip to content
Permalink
Browse files

Coverity memory leaks and other fixes

  • Loading branch information
nyalldawson committed May 27, 2015
1 parent 58f9372 commit 481b1647fc096ce8f26004050c43acfd8bcade59
@@ -514,7 +514,7 @@ QgsGeometry* QgsTransectSample::closestMultilineElement( const QgsPoint& pt, Qgs
double minDist = DBL_MAX;
double currentDist = 0;
QgsGeometry* currentLine = 0;
QgsGeometry* closestLine = 0;
QScopedPointer<QgsGeometry> closestLine;
QgsGeometry* pointGeom = QgsGeometry::fromPoint( pt );

QgsMultiPolyline multiPolyline = multiLine->asMultiPolyline();
@@ -526,7 +526,7 @@ QgsGeometry* QgsTransectSample::closestMultilineElement( const QgsPoint& pt, Qgs
if ( currentDist < minDist )
{
minDist = currentDist;
closestLine = currentLine;
closestLine.reset( currentLine );
}
else
{
@@ -535,7 +535,7 @@ QgsGeometry* QgsTransectSample::closestMultilineElement( const QgsPoint& pt, Qgs
}

delete pointGeom;
return closestLine;
return closestLine.take();
}

QgsGeometry* QgsTransectSample::clipBufferLine( const QgsGeometry* stratumGeom, QgsGeometry* clippedBaseline, double tolerance )
@@ -920,6 +920,7 @@ QgisApp::QgisApp()
, mBrowserWidget( 0 )
, mBrowserWidget2( 0 )
, mAdvancedDigitizingDockWidget( 0 )
, mStatisticalSummaryDockWidget( 0 )
, mSnappingDialog( 0 )
, mPluginManager( 0 )
, mComposerManager( 0 )
@@ -930,6 +931,7 @@ QgisApp::QgisApp()
, mLogViewer( 0 )
, mTrustedMacros( false )
, mMacrosWarn( 0 )
, mUserInputDockWidget( 0 )
, mVectorLayerTools( 0 )
, mBtnFilterLegend( 0 )
, mSnappingUtils( 0 )
@@ -6523,24 +6525,24 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
*/
if ( selectionLayer->type() == 0 )
{
//Getting the selectionLayer geometry
QgsVectorLayer *SelectionGeometry = static_cast<QgsVectorLayer*>(selectionLayer);
QString geoType = QString::number(SelectionGeometry->geometryType());
//Getting the selectionLayer geometry
QgsVectorLayer *SelectionGeometry = static_cast<QgsVectorLayer*>( selectionLayer );
QString geoType = QString::number( SelectionGeometry->geometryType() );

//Adding geometryinformation
QDomElement layerGeometryType = doc.createElement("layerGeometryType");
QDomText type = doc.createTextNode(geoType);
//Adding geometryinformation
QDomElement layerGeometryType = doc.createElement( "layerGeometryType" );
QDomText type = doc.createTextNode( geoType );

layerGeometryType.appendChild(type);
rootNode.appendChild(layerGeometryType);
layerGeometryType.appendChild( type );
rootNode.appendChild( layerGeometryType );
}

QString errorMsg;
if ( !selectionLayer->writeSymbology( rootNode, doc, errorMsg ) )
{
messageBar()->pushMessage( errorMsg,
tr( "Cannot copy style: %1" ),
QgsMessageBar::CRITICAL, messageTimeout() );
messageBar()->pushMessage( errorMsg,
tr( "Cannot copy style: %1" ),
QgsMessageBar::CRITICAL, messageTimeout() );
return;
}
// Copies data in text form as well, so the XML can be pasted into a text editor
@@ -6556,7 +6558,7 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )


void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )
{
{
QgsMapLayer *selectionLayer = destinationLayer ? destinationLayer : activeLayer();
if ( selectionLayer )
{
@@ -6568,34 +6570,34 @@ void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )
if ( !doc.setContent( clipboard()->data( QGSCLIPBOARD_STYLE_MIME ), false, &errorMsg, &errorLine, &errorColumn ) )
{

messageBar()->pushMessage( errorMsg,
tr( "Cannot parse style: %1:%2:%3" ),
QgsMessageBar::CRITICAL, messageTimeout() );
return;
messageBar()->pushMessage( errorMsg,
tr( "Cannot parse style: %1:%2:%3" ),
QgsMessageBar::CRITICAL, messageTimeout() );
return;
}

QDomElement rootNode = doc.firstChildElement( "qgis" );

//Test for matching geometry type on vector layers when pasting
if (selectionLayer->type() == QgsMapLayer::VectorLayer)
if ( selectionLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *selectionVectorLayer = static_cast<QgsVectorLayer*>(selectionLayer);
int pasteLayerGeometryType = doc.elementsByTagName("layerGeometryType").item(0).toElement().text().toInt();
if ( selectionVectorLayer->geometryType() != pasteLayerGeometryType )
{
messageBar()->pushMessage( tr( "Cannot paste style to layer with a different geometry type" ),
tr( "Your copied style does not match the layer you are pasting to" ),
QgsMessageBar::INFO, messageTimeout() );
return;
}
QgsVectorLayer *selectionVectorLayer = static_cast<QgsVectorLayer*>( selectionLayer );
int pasteLayerGeometryType = doc.elementsByTagName( "layerGeometryType" ).item( 0 ).toElement().text().toInt();
if ( selectionVectorLayer->geometryType() != pasteLayerGeometryType )
{
messageBar()->pushMessage( tr( "Cannot paste style to layer with a different geometry type" ),
tr( "Your copied style does not match the layer you are pasting to" ),
QgsMessageBar::INFO, messageTimeout() );
return;
}
}

if ( !selectionLayer->readSymbology( rootNode, errorMsg ) )
{
messageBar()->pushMessage( errorMsg,
tr( "Cannot read style: %1" ),
QgsMessageBar::CRITICAL, messageTimeout() );
return;
messageBar()->pushMessage( errorMsg,
tr( "Cannot read style: %1" ),
QgsMessageBar::CRITICAL, messageTimeout() );
return;
}

mLayerTreeView->refreshLayerSymbology( selectionLayer->id() );
@@ -183,6 +183,7 @@ QgsGeometry* QgsMapToolDeletePart::partUnderPoint( QPoint point, QgsFeatureId& f
delete geomPart;
return partGeo;
}
delete partGeo;
}
break;
}
@@ -88,6 +88,9 @@ void QgsMapToolDeleteRing::canvasPressEvent( QMouseEvent *e )
mRubberBand->setToGeometry( ringGeom, vlayer );
mRubberBand->show();
}

delete ringGeom;
ringGeom = 0;
}

void QgsMapToolDeleteRing::canvasReleaseEvent( QMouseEvent *e )
@@ -124,10 +127,10 @@ QgsGeometry* QgsMapToolDeleteRing::ringUnderPoint( QgsPoint p, QgsFeatureId& fid
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( toLayerCoordinates( vlayer, mCanvas->extent() ) ) );
QgsFeature f;
const QgsGeometry* g;
QgsGeometry* ringGeom = 0;
QScopedPointer<QgsGeometry> ringGeom;
QgsMultiPolygon pol;
QgsPolygon tempPol;
QgsGeometry* tempGeom;
QScopedPointer<QgsGeometry> tempGeom;
double area = std::numeric_limits<double>::max();
while ( fit.nextFeature( f ) )
{
@@ -150,20 +153,20 @@ QgsGeometry* QgsMapToolDeleteRing::ringUnderPoint( QgsPoint p, QgsFeatureId& fid
for ( int j = 1; j < pol[i].size();++j )
{
tempPol = QgsPolygon() << pol[i][j];
tempGeom = QgsGeometry::fromPolygon( tempPol );
tempGeom.reset( QgsGeometry::fromPolygon( tempPol ) );
if ( tempGeom->area() < area && tempGeom->contains( &p ) )
{
fid = f.id();
partNum = i;
ringNum = j;
ringGeom = tempGeom;
area = tempGeom->area();
ringGeom.reset( tempGeom.take() );
}
}
}
}
}
return ringGeom;
return ringGeom.take();
}


@@ -589,6 +589,8 @@ void QgsComposerMapGrid::calculateCRSTransformLines()
{
//look for intersections between lines
QgsGeometry* intersects = ( *yLineIt )->intersection(( *xLineIt ) );
if ( !intersects )
continue;

//go through all intersections and draw grid markers/crosses
int i = 0;
@@ -599,6 +601,7 @@ void QgsComposerMapGrid::calculateCRSTransformLines()
i = i + 1;
vertex = intersects->vertexAt( i );
}
delete intersects;
}
}
//clean up
@@ -413,7 +413,7 @@ void QgsCompoundCurveV2::addVertex( const QgsPointV2& pt )
}
else //create new QgsLineStringV2* with point in it
{
line = dynamic_cast<QgsLineStringV2*>( lastCurve );
line = static_cast<QgsLineStringV2*>( lastCurve );
}
line->addVertex( pt );
}
@@ -121,6 +121,10 @@ bool QgsCurvePolygonV2::fromWkb( const unsigned char* wkb )
{
currentCurve = new QgsCompoundCurveV2();
}
else
{
return false;
}
currentCurve->fromWkb( wkbPtr );
currentCurveSize = currentCurve->wkbSize();
if ( i == 0 )

0 comments on commit 481b164

Please sign in to comment.