Skip to content

Commit

Permalink
Fix some memory leaks exposed by Coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 3, 2015
1 parent 5cacf59 commit 005e158
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/analysis/interpolation/Node.h
Expand Up @@ -49,7 +49,7 @@ inline Node::Node() : mPoint( 0 ), mNext( 0 )

inline Node::~Node()
{

delete mPoint;
}

inline Node* Node::getNext() const
Expand Down
11 changes: 4 additions & 7 deletions src/app/qgisapp.cpp
Expand Up @@ -4957,13 +4957,13 @@ void QgisApp::saveAsRasterFile()
// TODO: show error dialogs
// TODO: this code should go somewhere else, but probably not into QgsRasterFileWriter
// clone pipe/provider is not really necessary, ready for threads
QgsRasterPipe* pipe = 0;
QScopedPointer<QgsRasterPipe> pipe( 0 );

if ( d.mode() == QgsRasterLayerSaveAsDialog::RawDataMode )
{
QgsDebugMsg( "Writing raw data" );
//QgsDebugMsg( QString( "Writing raw data" ).arg( pos ) );
pipe = new QgsRasterPipe();
pipe.reset( new QgsRasterPipe() );
if ( !pipe->set( rasterLayer->dataProvider()->clone() ) )
{
QgsDebugMsg( "Cannot set pipe provider" );
Expand Down Expand Up @@ -4997,20 +4997,18 @@ void QgisApp::saveAsRasterFile()
{
// clone the whole pipe
QgsDebugMsg( "Writing rendered image" );
pipe = new QgsRasterPipe( *rasterLayer->pipe() );
pipe.reset( new QgsRasterPipe( *rasterLayer->pipe() ) );
QgsRasterProjector *projector = pipe->projector();
if ( !projector )
{
QgsDebugMsg( "Cannot get pipe projector" );
delete pipe;
return;
}
projector->setCRS( rasterLayer->crs(), d.outputCrs() );
}

if ( !pipe->last() )
{
delete pipe;
return;
}
fileWriter.setCreateOptions( d.createOptions() );
Expand All @@ -5021,7 +5019,7 @@ void QgisApp::saveAsRasterFile()
fileWriter.setPyramidsFormat( d.pyramidsFormat() );
fileWriter.setPyramidsConfigOptions( d.pyramidsConfigOptions() );

QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe, d.nColumns(), d.nRows(), d.outputRectangle(), d.outputCrs(), &pd );
QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe.data(), d.nColumns(), d.nRows(), d.outputRectangle(), d.outputCrs(), &pd );
if ( err != QgsRasterFileWriter::NoError )
{
QMessageBox::warning( this, tr( "Error" ),
Expand All @@ -5033,7 +5031,6 @@ void QgisApp::saveAsRasterFile()
{
emit layerSavedAs( rasterLayer, d.outputFileName() );
}
delete pipe;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsclipboard.cpp
Expand Up @@ -169,12 +169,12 @@ QgsFeatureList QgsClipboard::copyOf( const QgsFields &fields )
if ( !geometry )
continue;

QgsFeature* feature = new QgsFeature();
QgsFeature feature;
if ( !fields.isEmpty() )
feature->setFields( &fields, true );
feature.setFields( &fields, true );

feature->setGeometry( geometry );
features.append( QgsFeature( *feature ) );
feature.setGeometry( geometry );
features.append( feature );
}

if ( features.isEmpty() )
Expand Down
4 changes: 3 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -477,7 +477,9 @@ void QgsRelationReferenceWidget::highlightFeature( QgsFeature f, CanvasExtent ca
}
else if ( canvasExtent == Pan )
{
QgsPoint center = geom->centroid()->asPoint();
QgsGeometry* centroid = geom->centroid();
QgsPoint center = centroid->asPoint();
delete centroid;
center = mCanvas->mapSettings().layerToMapCoordinates( mReferencedLayer, center );
mCanvas->zoomByFactor( 1.0, &center ); // refresh is done in this method
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -216,6 +216,7 @@ QgsValueRelationWidgetWrapper::ValueRelationCache QgsValueRelationWidgetWrapper:
cache.append( ValueRelationItem( f.attribute( ki ), f.attribute( vi ).toString() ) );
}
}
delete e;
}

if ( config.value( "OrderByValue" ).toBool() )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsattributeforminterface.cpp
Expand Up @@ -23,6 +23,10 @@ QgsAttributeFormInterface::QgsAttributeFormInterface( QgsAttributeForm* form )
{
}

QgsAttributeFormInterface::~QgsAttributeFormInterface()
{
}

bool QgsAttributeFormInterface::acceptChanges( const QgsFeature& feature )
{
Q_UNUSED( feature )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsattributeforminterface.h
Expand Up @@ -24,6 +24,8 @@ class GUI_EXPORT QgsAttributeFormInterface
public:
explicit QgsAttributeFormInterface( QgsAttributeForm* form );

virtual ~QgsAttributeFormInterface();

virtual bool acceptChanges( const QgsFeature& feature );

virtual void initForm();
Expand Down

0 comments on commit 005e158

Please sign in to comment.