@@ -69,6 +69,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
69
69
)
70
70
: mDS( NULL )
71
71
, mLayer( NULL )
72
+ , mOgrRef( NULL )
72
73
, mGeom( NULL )
73
74
, mError( NoError )
74
75
, mCodec( 0 )
@@ -260,12 +261,11 @@ QgsVectorFileWriter::QgsVectorFileWriter(
260
261
}
261
262
262
263
// consider spatial reference system of the layer
263
- OGRSpatialReferenceH ogrRef = NULL ;
264
264
if ( srs )
265
265
{
266
266
QString srsWkt = srs->toWkt ();
267
267
QgsDebugMsg ( " WKT to save as is " + srsWkt );
268
- ogrRef = OSRNewSpatialReference ( srsWkt.toLocal8Bit ().data () );
268
+ mOgrRef = OSRNewSpatialReference ( srsWkt.toLocal8Bit ().data () );
269
269
}
270
270
271
271
// datasource created, now create the output layer
@@ -285,7 +285,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
285
285
// disable encoding conversion of OGR Shapefile layer
286
286
CPLSetConfigOption ( " SHAPE_ENCODING" , " " );
287
287
288
- mLayer = OGR_DS_CreateLayer ( mDS , TO8F ( layerName ), ogrRef , wkbType, options );
288
+ mLayer = OGR_DS_CreateLayer ( mDS , TO8F ( layerName ), mOgrRef , wkbType, options );
289
289
290
290
if ( options )
291
291
{
@@ -318,8 +318,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
318
318
QgsDebugMsg ( " Couldn't open file " + layerName + " .qpj" );
319
319
}
320
320
}
321
-
322
- OSRDestroySpatialReference ( ogrRef );
323
321
}
324
322
325
323
if ( mLayer == NULL )
@@ -1829,6 +1827,11 @@ QgsVectorFileWriter::~QgsVectorFileWriter()
1829
1827
{
1830
1828
OGR_DS_Destroy ( mDS );
1831
1829
}
1830
+
1831
+ if ( mOgrRef )
1832
+ {
1833
+ OSRDestroySpatialReference ( mOgrRef );
1834
+ }
1832
1835
}
1833
1836
1834
1837
QgsVectorFileWriter::WriterError
0 commit comments