[geos-devel] [GEOS] #918: memory leak in GeometryCollection::getCoordinate()
GEOS
geos-trac at osgeo.org
Tue Aug 21 07:13:09 PDT 2018
#918: memory leak in GeometryCollection::getCoordinate()
------------------------+--------------------------
Reporter: basiliscos | Owner: geos-devel@…
Type: defect | Status: new
Priority: major | Milestone:
Component: Default | Version: 3.6.2
Severity: Unassigned | Keywords:
------------------------+--------------------------
The implementation is
{{{
const Coordinate*
GeometryCollection::getCoordinate() const
{
// should use auto_ptr here or return NULL or throw an exception !
// --strk;
if (isEmpty()) return new Coordinate();
return (*geometries)[0]->getCoordinate();
}
}}}
So, if a collection is empty it returns coordinate and (to prevent memory
leaks) assumes that caller should delete it. Otherwise it returns non-
owning Coordinate* and not delete is required from caller.
The best way is return NULL as it is told in the comment.
The alternative will be
{{{
...
static Coordinate zero;
if (isEmpty()) return &zero;
}}}
--
Ticket URL: <https://trac.osgeo.org/geos/ticket/918>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).
More information about the geos-devel
mailing list