[geos-commits] [SCM] GEOS branch master updated. d1556af8cddca70ef7872c9b157907cdf07a1f8a

git at osgeo.org git at osgeo.org
Thu Jun 13 18:53:34 PDT 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  d1556af8cddca70ef7872c9b157907cdf07a1f8a (commit)
      from  36d1c69636062de78688cb7e995eccbc27785287 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d1556af8cddca70ef7872c9b157907cdf07a1f8a
Author: Daniel Baston <dbaston at gmail.com>
Date:   Thu Jun 13 21:52:31 2019 -0400

    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

diff --git a/src/geom/GeometryCollection.cpp b/src/geom/GeometryCollection.cpp
index 51809c9..e07d6e0 100644
--- a/src/geom/GeometryCollection.cpp
+++ b/src/geom/GeometryCollection.cpp
@@ -270,14 +270,12 @@ GeometryCollection::compareToSameClass(const Geometry* g) const
 const Coordinate*
 GeometryCollection::getCoordinate() const
 {
-    // should use unique_ptr here or return NULL or throw an exception !
-    // 	--strk;
     for(size_t i = 0; i < geometries->size(); ++i) {
         if(!(*geometries)[i]->isEmpty()) {
             return (*geometries)[i]->getCoordinate();
         }
     }
-    return new Coordinate();
+    return nullptr;
 }
 
 /**
diff --git a/tests/unit/geom/GeometryCollectionTest.cpp b/tests/unit/geom/GeometryCollectionTest.cpp
index b2cf106..54ec1f8 100644
--- a/tests/unit/geom/GeometryCollectionTest.cpp
+++ b/tests/unit/geom/GeometryCollectionTest.cpp
@@ -81,4 +81,16 @@ void object::test<2>
     std::unique_ptr<Geometry> clone(geom_col->clone());
     ensure_equals(clone->getGeometryN(0)->getSRID(), 2);
 }
+
+template<>
+template<>
+void object::test<3>
+()
+{
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createGeometryCollection());
+
+    ensure(g->getCoordinate() == nullptr);
+}
 } // namespace tut
diff --git a/tests/unit/geom/LineStringTest.cpp b/tests/unit/geom/LineStringTest.cpp
index 91d640f..a04cbd1 100644
--- a/tests/unit/geom/LineStringTest.cpp
+++ b/tests/unit/geom/LineStringTest.cpp
@@ -512,5 +512,17 @@ void object::test<25>
     factory_->destroyGeometry(geo);
 }
 
+template<>
+template<>
+void object::test<26>
+()
+{
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = geos::geom::GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createLineString());
+
+    ensure(g->getCoordinate() == nullptr);
+}
+
 } // namespace tut
 
diff --git a/tests/unit/geom/LinearRingTest.cpp b/tests/unit/geom/LinearRingTest.cpp
index 42600d6..9a912d7 100644
--- a/tests/unit/geom/LinearRingTest.cpp
+++ b/tests/unit/geom/LinearRingTest.cpp
@@ -448,4 +448,16 @@ void object::test<30>
     const std::string type("LinearRing");
     ensure_equals(ring_->getGeometryType(), type);
 }
+
+template<>
+template<>
+void object::test<31>
+()
+{
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = geos::geom::GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createLinearRing());
+
+    ensure(g->getCoordinate() == nullptr);
+}
 } // namespace tut
diff --git a/tests/unit/geom/MultiLineStringTest.cpp b/tests/unit/geom/MultiLineStringTest.cpp
index 0d25f87..e2a43b9 100644
--- a/tests/unit/geom/MultiLineStringTest.cpp
+++ b/tests/unit/geom/MultiLineStringTest.cpp
@@ -3,6 +3,7 @@
 
 #include <tut/tut.hpp>
 // geos
+#include <geos/geom/GeometryFactory.h>
 #include <geos/geom/MultiLineString.h>
 
 namespace tut {
@@ -24,13 +25,16 @@ group test_multilinestring_group("geos::geom::MultiLineString");
 // Test Cases
 //
 
-// Test of default constructor
 template<>
 template<>
 void object::test<1>
 ()
 {
-    //inform("Test not implemented!");
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = geos::geom::GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createMultiLineString());
+
+    ensure(g->getCoordinate() == nullptr);
 }
 
 } // namespace tut
diff --git a/tests/unit/geom/MultiPointTest.cpp b/tests/unit/geom/MultiPointTest.cpp
index 1202587..a2bace0 100644
--- a/tests/unit/geom/MultiPointTest.cpp
+++ b/tests/unit/geom/MultiPointTest.cpp
@@ -392,5 +392,17 @@ void object::test<28>
     }
 }
 
+template<>
+template<>
+void object::test<29>
+()
+{
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = geos::geom::GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createMultiPoint());
+
+    ensure(g->getCoordinate() == nullptr);
+}
+
 } // namespace tut
 
diff --git a/tests/unit/geom/MultiPolygonTest.cpp b/tests/unit/geom/MultiPolygonTest.cpp
index 12ba16a..90ad0c6 100644
--- a/tests/unit/geom/MultiPolygonTest.cpp
+++ b/tests/unit/geom/MultiPolygonTest.cpp
@@ -3,6 +3,7 @@
 
 #include <tut/tut.hpp>
 // geos
+#include <geos/geom/GeometryFactory.h>
 #include <geos/geom/MultiPolygon.h>
 
 namespace tut {
@@ -24,13 +25,16 @@ group test_multipolygon_group("geos::geom::MultiPolygon");
 // Test Cases
 //
 
-// Test of default constructor
 template<>
 template<>
 void object::test<1>
 ()
 {
-    //inform("Test not implemented!");
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = geos::geom::GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createMultiPolygon());
+
+    ensure(g->getCoordinate() == nullptr);
 }
 
 } // namespace tut
diff --git a/tests/unit/geom/PointTest.cpp b/tests/unit/geom/PointTest.cpp
index 39b49ef..a935f42 100644
--- a/tests/unit/geom/PointTest.cpp
+++ b/tests/unit/geom/PointTest.cpp
@@ -564,5 +564,17 @@ void object::test<40>
     delete p;
 }
 
+template<>
+template<>
+void object::test<41>
+()
+{
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = geos::geom::GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createPoint());
+
+    ensure(g->getCoordinate() == nullptr);
+}
+
 } // namespace tut
 
diff --git a/tests/unit/geom/PolygonTest.cpp b/tests/unit/geom/PolygonTest.cpp
index 8713e0d..21f3279 100644
--- a/tests/unit/geom/PolygonTest.cpp
+++ b/tests/unit/geom/PolygonTest.cpp
@@ -591,4 +591,16 @@ void object::test<39>
     ensure(gBuffer->getNumPoints() == poly_->getNumPoints());
 }
 
+template<>
+template<>
+void object::test<40>
+()
+{
+    // getCoordinate() returns nullptr for empty geometry
+    auto gf = geos::geom::GeometryFactory::create();
+    std::unique_ptr<geos::geom::Geometry> g(gf->createPolygon());
+
+    ensure(g->getCoordinate() == nullptr);
+}
+
 } // namespace tut

-----------------------------------------------------------------------

Summary of changes:
 src/geom/GeometryCollection.cpp            |  4 +---
 tests/unit/geom/GeometryCollectionTest.cpp | 12 ++++++++++++
 tests/unit/geom/LineStringTest.cpp         | 12 ++++++++++++
 tests/unit/geom/LinearRingTest.cpp         | 12 ++++++++++++
 tests/unit/geom/MultiLineStringTest.cpp    |  8 ++++++--
 tests/unit/geom/MultiPointTest.cpp         | 12 ++++++++++++
 tests/unit/geom/MultiPolygonTest.cpp       |  8 ++++++--
 tests/unit/geom/PointTest.cpp              | 12 ++++++++++++
 tests/unit/geom/PolygonTest.cpp            | 12 ++++++++++++
 9 files changed, 85 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list