[geos-commits] [SCM] GEOS branch 3.8 updated. d1f6bc89e2748ffb3f64e9ea53c0ec42c55a0c0e

git at osgeo.org git at osgeo.org
Sat Dec 19 16:52:10 PST 2020


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, 3.8 has been updated
       via  d1f6bc89e2748ffb3f64e9ea53c0ec42c55a0c0e (commit)
       via  a798ab80b9879a64b31ee662964eb8d3de8ea2ac (commit)
      from  2ccac9cc0833290a26a58633730b33f39e16d407 (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 d1f6bc89e2748ffb3f64e9ea53c0ec42c55a0c0e
Merge: a798ab8 2ccac9c
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Sat Dec 19 16:51:58 2020 -0800

    Merge branch '3.8' of https://git.osgeo.org/gitea/geos/geos into 3.8


commit a798ab80b9879a64b31ee662964eb8d3de8ea2ac
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Sat Dec 19 16:51:50 2020 -0800

    Fix memory management quirk for Win32 in CAPI (closes #1050)

diff --git a/NEWS b/NEWS
index 70abeed..03419be 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Changes in 3.8.2dev
   - Fix segfault in GEOSInterpolate against empty eollections (#1055,
     Sandro Santilli)
   - Fix GEOSProjectNormalized return -1 on exception (#1058, Joris Van den Bossche)
+  - Fix memory management quirk in CAPI (#1050, Paul Ramsey)
 
 
 Changes in 3.8.1
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 763be98..e1b883a 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -4411,16 +4411,21 @@ extern "C" {
         try {
             using geos::geom::LinearRing;
 
-            auto vholes = geos::detail::make_unique<std::vector<LinearRing*>>(nholes);
-
+            /*
+            * First check that we can cast these generic
+            * geometry pointers into linearrings. Then
+            * convert them to unique_ptr to pass to the constructor
+            * so we can get a no-copy transfer of the data
+            */
+            std::vector<LinearRing*> tmpholes(nholes);
             for (size_t i = 0; i < nholes; i++) {
-                (*vholes)[i] = dynamic_cast<LinearRing*>(holes[i]);
-                if ((*vholes)[i] == nullptr) {
+                LinearRing* lr = dynamic_cast<LinearRing*>(holes[i]);
+                if (! lr) {
                     handle->ERROR_MESSAGE("Hole is not a LinearRing");
                     return NULL;
                 }
+                tmpholes[i] = lr;
             }
-
             LinearRing* nshell = dynamic_cast<LinearRing*>(shell);
             if(! nshell) {
                 handle->ERROR_MESSAGE("Shell is not a LinearRing");
@@ -4428,7 +4433,15 @@ extern "C" {
             }
             const GeometryFactory* gf = handle->geomFactory;
 
-            return gf->createPolygon(nshell, vholes.release());
+            /* Create unique_ptr version for constructor */
+            std::vector<std::unique_ptr<LinearRing>> vholes;
+            vholes.reserve(nholes);
+            for (LinearRing* lr: tmpholes) {
+                vholes.emplace_back(lr);
+            }
+            std::unique_ptr<LinearRing> shell(nshell);
+
+            return gf->createPolygon(std::move(shell), std::move(vholes)).release();
         }
         catch(const std::exception& e) {
             handle->ERROR_MESSAGE("%s", e.what());

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

Summary of changes:
 NEWS               |  1 +
 capi/geos_ts_c.cpp | 25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list