Opened 6 years ago
Closed 5 years ago
#918 closed defect (fixed)
memory leak in GeometryCollection::getCoordinate()
Reported by: | basiliscos | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Default | Version: | 3.6.2 |
Severity: | Unassigned | Keywords: | |
Cc: |
Description
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;
Note:
See TracTickets
for help on using tickets.
In d1556af/git: