Skip to content
Permalink
Browse files

Fix large memory leak in vector file writer (fix #16003)

(cherry-picked from 826a86)
  • Loading branch information
nyalldawson committed Feb 13, 2017
1 parent 34e307b commit 119e1815f3f12afbebab20989ad9cbe76242e4bb
Showing with 5 additions and 17 deletions.
  1. +5 −16 src/core/qgsvectorfilewriter.cpp
  2. +0 −1 src/core/qgsvectorfilewriter.h
@@ -86,7 +86,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
: mDS( nullptr )
, mLayer( nullptr )
, mOgrRef( nullptr )
, mGeom( nullptr )
, mError( NoError )
, mCodec( nullptr )
, mWkbType( QGis::fromOldWkbType( geometryType ) )
@@ -103,7 +102,6 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& vectorFileName, const Q
: mDS( nullptr )
, mLayer( nullptr )
, mOgrRef( nullptr )
, mGeom( nullptr )
, mError( NoError )
, mCodec( nullptr )
, mWkbType( geometryType )
@@ -132,7 +130,6 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& vectorFileName,
: mDS( nullptr )
, mLayer( nullptr )
, mOgrRef( nullptr )
, mGeom( nullptr )
, mError( NoError )
, mCodec( nullptr )
, mWkbType( geometryType )
@@ -692,11 +689,6 @@ void QgsVectorFileWriter::init( QString vectorFileName,
QgsDebugMsg( "Done creating fields" );

mWkbType = geometryType;
if ( mWkbType != QgsWKBTypes::NoGeometry )
{
// create geometry which will be used for import
mGeom = createEmptyGeometry( mWkbType );
}

if ( newFilename )
*newFilename = vectorFileName;
@@ -2133,7 +2125,9 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
}
else // wkb type matches
{
OGRErr err = OGR_G_ImportFromWkb( mGeom, const_cast<unsigned char *>( geom->asWkb() ), static_cast< int >( geom->wkbSize() ) );
OGRGeometryH ogrGeom = createEmptyGeometry( mWkbType );
OGRErr err = OGR_G_ImportFromWkb( ogrGeom, const_cast<unsigned char *>( geom->asWkb() ), static_cast< int >( geom->wkbSize() ) );

if ( err != OGRERR_NONE )
{
mErrorMessage = QObject::tr( "Feature geometry not imported (OGR error: %1)" )
@@ -2144,8 +2138,8 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
return nullptr;
}

// set geometry (ownership is not passed to OGR)
OGR_F_SetGeometry( poFeature, mGeom );
// set geometry (ownership is passed to OGR)
OGR_F_SetGeometryDirectly( poFeature, ogrGeom );
}
}
else
@@ -2182,11 +2176,6 @@ bool QgsVectorFileWriter::writeFeature( OGRLayerH layer, OGRFeatureH feature )

QgsVectorFileWriter::~QgsVectorFileWriter()
{
if ( mGeom )
{
OGR_G_DestroyGeometry( mGeom );
}

if ( mDS )
{
OGR_DS_Destroy( mDS );
@@ -517,7 +517,6 @@ class CORE_EXPORT QgsVectorFileWriter
OGRDataSourceH mDS;
OGRLayerH mLayer;
OGRSpatialReferenceH mOgrRef;
OGRGeometryH mGeom;

QgsFields mFields;

0 comments on commit 119e181

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