Ticket #367 (closed defect: fixed)
Segmentation fault in distance() method.
|Reported by:||yabo||Owned by:||strk|
I have a segmentation fault in Geometry::distance between these geometries (obviously the first one is the problem):
g1: 01060000000100000001030000000100000000000000 g2: 010100000000000000000000000000000000000000
g1 is a MULTIPOLYGON((EMPTY)) (this is what st_astext pretends).
The segmentation fault is produced here :
GeometryLocation (this=0x605bc0, newComponent=0x6048a0, newSegIndex=0, newPt=...) at GeometryLocation.cpp:37 pt = newPt;
This is because newPt is 0x0 (NULL). The derefencing of the NULL pointer occured here :
geos::operation::distance::ConnectedElementLocationFilter::filter_ro (this=0x7fffffffdcc0, geom=0x6048a0) at ConnectedElementLocationFilter.cpp:56 locations->push_back(new GeometryLocation(geom, 0, *(geom->getCoordinate())));
The faulty code is the *(geom->getCoordinate()). Indeed, g1 is loaded as an empty polygon. Polygon::getCoordinate() returns shell->getCoordinate() which in turns returns NULL if the shell is empty.
Note that this is not coherent with GeometryCollection::getCoordinate() which returns 'new Coordinate()' if empty.
Actually I find the GeometryCollection? solution quite ugly. More than that, it leaks memory :( (and there is a FIXME from strk by the way).
I don't know what the best fix could be. Return 0 in distance ? Throw an exception ?
This is all with geos-trunk and geos-3.2.1.