Ticket #1680 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

NG SWIG OGRSpatialReference Ref Counts

Reported by: warmerdam Owned by: warmerdam
Priority: normal Milestone: 1.4.2
Component: PythonBindings Version: svn-trunk
Severity: normal Keywords: refcounting OGRSpatialReference
Cc: hobu

Description

It seems that the OGRLayer::GetSpatialRef?() call in gdal/swig/include/ogr.i is not taking a reference on the returned OGRSpatialReference, and that such objects are not dereferenced when they are unreferenced from the script.

This leads to the situation, in python, where:

    ds = ogr.Open( 'data/small_ntf.mif' )
    srs = ds.GetLayer(0).GetSpatialRef()
    ds = None

    pm_value = srs.GetAttrValue( 'PROJCS|GEOGCS|PRIMEM',1)

does not work properly because by the time srs.GetAttrValue?() is called the SRS was already destroyed (when the datasource was destroyed).

Note that osr.py does implicitly get a reference when an OGRSpatialReference is directly created, and it is properly dereferenced on destruction.

I observed this in trunk.

While I'm marking this as PythonBindings?, I presume it applies to all NG swig bindings.

Change History

Changed 5 years ago by warmerdam

  • cc hobu added

Changed 5 years ago by hobu

attempted to fix with r11678

Changed 5 years ago by warmerdam

Complete tested fix with r11679 in trunk.

Adding indirect testing of this issue in the ogr_mitab.py script.

Not sure if I dare backport to 1.4 branch.

Changed 5 years ago by warmerdam

  • status changed from new to closed
  • resolution set to fixed

Fixed and verified in 1.4 branch as well.

Closing.

Note: See TracTickets for help on using tickets.