[GEOS] #918: memory leak in GeometryCollection::getCoordinate()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[GEOS] #918: memory leak in GeometryCollection::getCoordinate()

geos-2
#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).

_______________________________________________
geos-devel mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/geos-devel
Reply | Threaded
Open this post in threaded view
|

Re: [GEOS] #918: memory leak in GeometryCollection::getCoordinate()

geos-2
#918: memory leak in GeometryCollection::getCoordinate()
------------------------+---------------------------
 Reporter:  basiliscos  |       Owner:  geos-devel@…
     Type:  defect      |      Status:  closed
 Priority:  major       |   Milestone:
Component:  Default     |     Version:  3.6.2
 Severity:  Unassigned  |  Resolution:  fixed
 Keywords:              |
------------------------+---------------------------
Changes (by Daniel Baston <dbaston@…>):

 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"d1556af8cddca70ef7872c9b157907cdf07a1f8a/git" d1556af/git]:
 {{{
 #!CommitTicketReference repository="git"
 revision="d1556af8cddca70ef7872c9b157907cdf07a1f8a"
 Fix memory leak on GeometryCollection::getCoordinate

 Add tests to ensure all Geometry types have the same behavior when
 calling getCoordinate on an empty geometry.

 Fixes #918
 }}}

--
Ticket URL: <https://trac.osgeo.org/geos/ticket/918#comment:1>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).

_______________________________________________
geos-devel mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/geos-devel