Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1674 closed defect (fixed)

GetDriver method of newly opened Datasource segfaults

Reported by: Ari Jolma Owned by: warmerdam
Priority: normal Milestone: 1.4.2
Component: OGR_SF Version: unspecified
Severity: normal Keywords: mem
Cc: hobu

Description (last modified by Mateusz Łoskot)

Code like:

use Geo::GDAL;

#$driver = Geo::OGR::GetDriverByName('Memory');
$driver = Geo::OGR::GetDriverByName('Esri Shapefile');

$datasource = $driver->CreateDataSource('x');

$datasource->GetDriver;

causes a segafault:

with Memory driver:

#0  0x001aa473 in strlen () from /lib/libc.so.6
#1  0x0105b3f8 in CPLStat () from /usr/local/lib/libgdal.so.1
#2  0x0111981a in OGRShapeDataSource::Open () from /usr/local/lib/libgdal.so.1
#3  0x0111a7c6 in OGRShapeDriver::Open () from /usr/local/lib/libgdal.so.1
#4  0x01118a5d in OGRSFDriverRegistrar::Open ()
   from /usr/local/lib/libgdal.so.1
#5  0x01118d97 in OGROpen () from /usr/local/lib/libgdal.so.1
#6  0x00720f8c in _wrap_DataSource_GetDriver (my_perl=0x9167008, cv=0x9284930)
    at ogr_wrap.cpp:1788

with Shapefile driver:

#0  0x01025562 in OGRSFDriverRegistrar::ReleaseDataSource ()
   from /usr/local/lib/libgdal.so.1
#1  0x010259cc in OGRReleaseDataSource () from /usr/local/lib/libgdal.so.1
#2  0x00884f94 in _wrap_DataSource_GetDriver (my_perl=0x9eb6008, cv=0x9fd3930)
    at ogr_wrap.cpp:1789

The problem does not appear if the datasource is opened, not created.

Change History (4)

comment:1 Changed 12 years ago by hobu

The following Python provokes it as well... Is this just incorrect usage? Even though, it shouldn't cause a segfault, I suppose.

import ogr
d = ogr.GetDriverByName('Memory')
ds = d.CreateDataSource('x')
d2 = ds.GetDriver()
#0  0x0118805f in CPLStat ()
#1  0x0124ab74 in OGRShapeDataSource::Open ()
#2  0x0124b7ec in OGRShapeDriver::Open ()
#3  0x0124980c in OGRSFDriverRegistrar::Open ()
#4  0x002178ee in _wrap_DataSource_GetDriver (args=0x7f390) at ogr_wrap.cpp:2909
#5  0x97e457fe in PyObject_Call ()
#6  0x97e96450 in _PyEval_SliceIndex ()
#7  0x97e97a98 in PyEval_EvalCodeEx ()
#8  0x97e95f6d in _PyEval_SliceIndex ()
#9  0x97e97a98 in PyEval_EvalCodeEx ()
#10 0x97e97bbb in PyEval_EvalCode ()
#11 0x97eb0dc5 in PyErr_Display ()
#12 0x97eb295a in PyRun_SimpleFileExFlags ()
#13 0x97eba42b in Py_Main ()
#14 0x00001f8e in start ()

comment:2 Changed 12 years ago by warmerdam

Cc: hobu added
Component: defaultOGR_SF
Keywords: mem added
Milestone: 1.4.2
Status: newassigned

On review, the problem is that the OGRMemDataSource does not record it's name. So OGR_DS_GetName() returns NULL which is passed to the open and subsequently to the CPLStat() function.

I am correcting this in trunk and 1.4 branch.

The issue is specific to the MEM driver, and not particularly to the GetDriver?() method.

comment:3 Changed 12 years ago by warmerdam

Resolution: fixed
Status: assignedclosed

It turns out there was two problems. One was that the MEM driver did not record it's datasource name. The other was that ogr.i's GetDriver?() attempted to release the datasource even if it was NULL.

One correction is in gdal/ogr/ogrsf_frmts/mem/ogrmemdatasource.cpp.

The other in gdal/swig/include/ogr.i

Both done in trunk and 1.4 branch.

comment:4 Changed 12 years ago by Mateusz Łoskot

Description: modified (diff)
Note: See TracTickets for help on using tickets.