Opened 17 years ago

Closed 17 years ago

#1680 closed defect (fixed)

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 (4)

comment:1 by warmerdam, 17 years ago

Cc: hobu added

comment:2 by hobu, 17 years ago

attempted to fix with r11678

comment:3 by warmerdam, 17 years ago

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.

comment:4 by warmerdam, 17 years ago

Resolution: fixed
Status: newclosed

Fixed and verified in 1.4 branch as well.

Closing.

Note: See TracTickets for help on using tickets.