Opened 5 years ago

Closed 5 years ago

#7175 closed defect (wontfix)

GetLayerDefn cause segmentation fault

Reported by: dr Owned by: hobu
Priority: normal Milestone:
Component: PythonBindings Version: 2.2.2
Severity: normal Keywords:


I get segmentation fault (core dumped) with the following code (sometimes need to repeat two last strings of code for getting crash). If move code outside the function all works fine. Is it expected behaviour?

from osgeo import ogr, gdal
def f(response, fname='output.gml'):
    gdal.FileFromMemBuffer('/vsimem/%s' % (fname, ), response)
    ds = ogr.Open('/vsimem/%s' % (fname, ))
    return ds.GetLayer(0)

xsd_content = """<ogr:FeatureCollection xmlns:gml="" xmlns:ogr="">
      <ogr:geometry><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,49 2,50 3,50 3,49 2,49</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometry>
      <ogr:otherGeometry><gml:Point><gml:pos>-2 -49</gml:pos></gml:Point></ogr:otherGeometry>
lyr = f(xsd_content)

Change History (1)

comment:1 by Even Rouault, 5 years ago

Resolution: wontfix
Status: newclosed

This is one of the gotchas of the python bindings (see ) . As soon as ds gets out of scope, the native resource associate to it gets destroyed. So your f function should return (ds, ds.GetLayer(0))

Note: See TracTickets for help on using tickets.