[gdal-dev] Clarification about ownership of srs passed to GDALDatasetCreateLayer()?

Sean Gillies sean at mapbox.com
Fri Apr 21 04:09:22 PDT 2017


Thanks, Even!

On Fri, Apr 21, 2017 at 11:14 AM, Even Rouault <even.rouault at spatialys.com>
wrote:

> On vendredi 21 avril 2017 10:57:16 CEST Sean Gillies wrote:
>
> > Hi all,
>
> >
>
> > I've written some C code (in one of Fiona's extension modules) that
>
> >
>
> > 1. sets a OGRSpatialReferenceH using OSRSetFromUserInput()
>
> > 2. passes this OGRSpatialReferenceH to GDALDatasetCreateLayer()
>
> > 3. frees the OGRSpatialReferenceH using OSRDestroySpatialReference()
>
>
>
> Please use OSRRelease() instead. It is always safe to use in all
> situations where you would use OSRDestroySpatialReference().
>
>
>
> > 4. adds feature definitions and features to the layer
>
> > 4. calls GDALClose() on the layer's dataset
>
> >
>
> > When using the Shapefile driver, this code always works. When using the
>
> > GPKG driver on Mac OS X and Windows (reports at
>
> > https://github.com/Toblerity/Fiona/issues/441) sporadic crashes occur in
>
> > OGRSpatialReference::Release() as the dataset is closed and the table,
>
> > feature definition, and geometry field definition is torn down.
>
> >
>
> > Does a created layer take ownership of the OGRSpatialReferenceH?
>
> > What's the
>
> > difference in the implementation of Shapefile and GPKG layers?
>
>
>
> The shapefile driver clones the passed object, whereas the GPKG only
> increments the reference counter. The ownership contract in the doc was not
> mentionned. I've just added """ The driver might only increase
>
> the reference counter of the object to take ownership, and not make a full
> copy,
>
> so do not use OSRDestroySpatialReference(), but OSRRelease() instead when
> you
>
> are done with the object."""
>
>
>
> Even
>
>
>
> --
>
> Spatialys - Geospatial professional services
>
> http://www.spatialys.com
>



-- 
Sean Gillies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170421/1770793c/attachment.html>


More information about the gdal-dev mailing list