Opened 12 years ago

Closed 12 years ago

#4858 closed defect (wontfix)

Segfault from ogr.OLCCreateField

Reported by: ktaylora Owned by: hobu
Priority: normal Milestone:
Component: PythonBindings Version: 1.7.3
Severity: normal Keywords: FieldDefn, CreateField, Segfault
Cc:

Description

Using Linux 3.4.11-1.fc16.x86_64, SMP GNU/Linux (Fedora)

When attempting to create a new shapefile and populate a layer with a field value from ogr.FieldDefn() using CreateField(), I get a segfault.

Attachments (1)

test.py (673 bytes ) - added by ktaylora 12 years ago.
Sample python code causing the segfault.

Download all attachments as: .zip

Change History (2)

by ktaylora, 12 years ago

Attachment: test.py added

Sample python code causing the segfault.

comment:1 by Even Rouault, 12 years ago

Resolution: wontfix
Status: newclosed

Yes, this is expected. You cannot modify the layer definition (for example calling CreateField()), while there is at least one instance of a feature of that layer still alive. See http://gdal.org/ogr/ogr__api_8h.html#aab585ef1166c61c4819f7fd46ee4a275

Basically, you must call CreateField() before ogr.Feature(outLayer_points.GetLayerDefn()) (or drop the feature reference before calling CreateField()).

This is due how the underlying C++ code works. The Feature object has an array whose size is equal to the number of fields in the layer definition, at the time it is instanciated. If the layer definition changes afterward, the feature object is then out-of-sync with it, and when it is finally destroyed, there's a mismatch between the definition it expects, and the actual array size.

This one of the "gotchas" documented in http://trac.osgeo.org/gdal/wiki/PythonGotchas (see "Python crashes if you add a new field to an OGR layer when features deriving from this layer definition are still active" section)

Note: See TracTickets for help on using tickets.