Skip to content

Commit

Permalink
Coverity memory leaks and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 27, 2015
1 parent 58f9372 commit 481b164
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/analysis/vector/qgstransectsample.cpp
Expand Up @@ -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();
Expand All @@ -526,7 +526,7 @@ QgsGeometry* QgsTransectSample::closestMultilineElement( const QgsPoint& pt, Qgs
if ( currentDist < minDist )
{
minDist = currentDist;
closestLine = currentLine;
closestLine.reset( currentLine );
}
else
{
Expand All @@ -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 )
Expand Down
62 changes: 32 additions & 30 deletions src/app/qgisapp.cpp
Expand Up @@ -920,6 +920,7 @@ QgisApp::QgisApp()
, mBrowserWidget( 0 )
, mBrowserWidget2( 0 )
, mAdvancedDigitizingDockWidget( 0 )
, mStatisticalSummaryDockWidget( 0 )
, mSnappingDialog( 0 )
, mPluginManager( 0 )
, mComposerManager( 0 )
Expand All @@ -930,6 +931,7 @@ QgisApp::QgisApp()
, mLogViewer( 0 )
, mTrustedMacros( false )
, mMacrosWarn( 0 )
, mUserInputDockWidget( 0 )
, mVectorLayerTools( 0 )
, mBtnFilterLegend( 0 )
, mSnappingUtils( 0 )
Expand Down Expand Up @@ -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
Expand All @@ -6556,7 +6558,7 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )


void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )
{
{
QgsMapLayer *selectionLayer = destinationLayer ? destinationLayer : activeLayer();
if ( selectionLayer )
{
Expand All @@ -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() );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmaptooldeletepart.cpp
Expand Up @@ -183,6 +183,7 @@ QgsGeometry* QgsMapToolDeletePart::partUnderPoint( QPoint point, QgsFeatureId& f
delete geomPart;
return partGeo;
}
delete partGeo;
}
break;
}
Expand Down
13 changes: 8 additions & 5 deletions src/app/qgsmaptooldeletering.cpp
Expand Up @@ -88,6 +88,9 @@ void QgsMapToolDeleteRing::canvasPressEvent( QMouseEvent *e )
mRubberBand->setToGeometry( ringGeom, vlayer );
mRubberBand->show();
}

delete ringGeom;
ringGeom = 0;
}

void QgsMapToolDeleteRing::canvasReleaseEvent( QMouseEvent *e )
Expand Down Expand Up @@ -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 ) )
{
Expand All @@ -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();
}


Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposermapgrid.cpp
Expand Up @@ -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;
Expand All @@ -599,6 +601,7 @@ void QgsComposerMapGrid::calculateCRSTransformLines()
i = i + 1;
vertex = intersects->vertexAt( i );
}
delete intersects;
}
}
//clean up
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscompoundcurvev2.cpp
Expand 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 );
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit 481b164

Please sign in to comment.