@@ -69,6 +69,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
6969)
7070 : mDS( NULL )
7171 , mLayer( NULL )
72+ , mOgrRef( NULL )
7273 , mGeom( NULL )
7374 , mError( NoError )
7475 , mCodec( 0 )
@@ -260,12 +261,11 @@ QgsVectorFileWriter::QgsVectorFileWriter(
260261 }
261262
262263 // consider spatial reference system of the layer
263- OGRSpatialReferenceH ogrRef = NULL ;
264264 if ( srs )
265265 {
266266 QString srsWkt = srs->toWkt ();
267267 QgsDebugMsg ( " WKT to save as is " + srsWkt );
268- ogrRef = OSRNewSpatialReference ( srsWkt.toLocal8Bit ().data () );
268+ mOgrRef = OSRNewSpatialReference ( srsWkt.toLocal8Bit ().data () );
269269 }
270270
271271 // datasource created, now create the output layer
@@ -285,7 +285,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
285285 // disable encoding conversion of OGR Shapefile layer
286286 CPLSetConfigOption ( " SHAPE_ENCODING" , " " );
287287
288- mLayer = OGR_DS_CreateLayer ( mDS , TO8F ( layerName ), ogrRef , wkbType, options );
288+ mLayer = OGR_DS_CreateLayer ( mDS , TO8F ( layerName ), mOgrRef , wkbType, options );
289289
290290 if ( options )
291291 {
@@ -318,8 +318,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
318318 QgsDebugMsg ( " Couldn't open file " + layerName + " .qpj" );
319319 }
320320 }
321-
322- OSRDestroySpatialReference ( ogrRef );
323321 }
324322
325323 if ( mLayer == NULL )
@@ -1829,6 +1827,11 @@ QgsVectorFileWriter::~QgsVectorFileWriter()
18291827 {
18301828 OGR_DS_Destroy ( mDS );
18311829 }
1830+
1831+ if ( mOgrRef )
1832+ {
1833+ OSRDestroySpatialReference ( mOgrRef );
1834+ }
18321835}
18331836
18341837QgsVectorFileWriter::WriterError
0 commit comments