Opened 6 years ago

Closed 6 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:
Cc:

Description

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="http://www.opengis.net/gml" xmlns:ogr="http://ogr.maptools.org/">
  <gml:featureMember>
    <ogr:test>
      <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>
    </ogr:test>
  </gml:featureMember>
</ogr:FeatureCollection>
"""
lyr = f(xsd_content)
lyr.GetLayerDefn()

Change History (1)

comment:1 by Even Rouault, 6 years ago

Resolution: wontfix
Status: newclosed

This is one of the gotchas of the python bindings (see https://trac.osgeo.org/gdal/wiki/PythonGotchas ) . 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.