Opened 8 years ago

Closed 7 years ago

#5300 closed defect (wontfix)

python binding : GetFeature() / GetNextFeature().GetGeometryRef() crashes

Reported by: elpaso Owned by: hobu
Priority: normal Milestone:
Component: PythonBindings Version: 1.9.2
Severity: normal Keywords:


This is the code:

from osgeo import ogr

driver = ogr.GetDriverByName('ESRI Shapefile')

shape_srs = ogr.osr.SpatialReference()

dest_srs = ogr.osr.SpatialReference()

layer = shape_handle.GetLayerByIndex(0)
g = layer.GetFeature(0).geometry()

I'm on Ubuntu 12.04 64 bit LTS, python-gdal:

Installed: 1.9.2-2~precise4

gdal.VersionInfo?() '1920'

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5c3165f in OGRGeometry::transformTo(OGRSpatialReference*) () from /usr/lib/
(gdb) bt
#0  0x00007ffff5c3165f in OGRGeometry::transformTo(OGRSpatialReference*) () from /usr/lib/
#1  0x00007fffe7e099a7 in ?? () from /usr/lib/python2.7/dist-packages/osgeo/
#2  0x000000000048abb8 in PyEval_EvalFrameEx ()
#3  0x000000000048d930 in PyEval_EvalCodeEx ()
#4  0x0000000000486bb8 in PyEval_EvalFrameEx ()
#5  0x000000000048d930 in PyEval_EvalCodeEx ()
#6  0x00000000004246a1 in PyRun_FileExFlags ()
#7  0x000000000042492e in PyRun_SimpleFileExFlags ()
#8  0x0000000000425cb6 in Py_Main ()
#9  0x00007ffff68cb76d in __libc_start_main () from /lib/x86_64-linux-gnu/
#10 0x000000000041bb31 in _start ()

Attachments (1) (4.7 KB) - added by elpaso 8 years ago.
Test shapefile

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by elpaso

Attachment: added

Test shapefile

comment:1 Changed 8 years ago by Even Rouault

Component: defaultPythonBindings
Owner: changed from warmerdam to hobu
Summary: python binding core dump on TransformTopython binding : GetFeature() / GetNextFeature().GetGeometryRef() crashes

Yes, this is a known limitation of how ref-counting in the Python bindings works. This is mentionned in the "Python gotchas" wiki page at . particularly in the section "Python crashes if you use an object after deleting an object it has a relationship with"

So you have to change a bit your code like this : feat = layer.GetFeature?(0) g = feat.geometry()

So that the feature object stays alive while you need its geometry.

comment:2 Changed 7 years ago by Even Rouault

Resolution: wontfix
Status: newclosed

Closing as wontfix for now. There are other tickets related to that

Note: See TracTickets for help on using tickets.