[gdal-dev] python/OGR error: interpreter crashes calling geometries method stored inside a python list

Howard Butler hobu.inc at gmail.com
Wed May 6 11:09:32 EDT 2009


On May 6, 2009, at 10:02 AM, G. Allegri wrote:
> geometries = [features[i].GetGeometryRef() for i in  
> range(len(features))]

features[i] is a temporary and goes poof once it goes out of scope.   
GetGeometryRef depends on features[i] staying alive for *its* entire  
lifetime as well.  In short, you can't depend on the reference  
counting of the objects in this instance.

I will note this is awful, but it should not segfault:

geometries =  
[ogr.CreateGeometryFromWkb(features[i].GetGeometryRef().ExportToWkb())  
for i in range(len(features))]




More information about the gdal-dev mailing list