[geos-devel] Proposed fix for #169 - memory leak

Denise MacLeod Denise.MacLeod at ingres.com
Thu Oct 23 10:06:41 EDT 2008


Hi all -

I'm relatively new to GEOS, and decided to poke around at some of the outstanding issues to get better acquainted.  I started with the memory leak from http://trac.osgeo.org/geos/ticket/169

Here's what was causing the leak:
-  GEOSisValid calls IsValidOp::isValid() and IsValidOp::getValidationError().
-  Both of these methods call IsValidOp::checkValid(const Geometry *g)
-  The first time IsValidOp::checkValid is called, isChecked is false and validErr is NULL. An error is found, a new TopologyValidationError object is created and assigned to validErr, but isChecked is still false.
- Subsequent calls to IsValidOp::checkValid, isChecked is still false, validErr is assigned NULL, losing the previous TopologyValidationError object. A new TVE object is later allocated and assigned to validErr, isChecked is still false.

The fix:
- at the end of IsValidOp::checkValid(const Geometry *g), set isChecked to true. validErr is either still NULL (if no error was found) or it may point to a TVE object.

I did not originally download the svn trunk version, so I can't create a proper patch, but here is my diff from the geos-3.0.0 version that I downloaded in Sept.  The change is on line 129.

[denise at localhost valid]$ diff -C5 IsValidOp.cpp.orig IsValidOp.cpp
*** IsValidOp.cpp.orig  2008-10-22 14:02:31.000000000 -0400
--- IsValidOp.cpp       2008-10-23 09:54:46.000000000 -0400
***************
*** 124,133 ****
--- 124,134 ----
        else if (typeid(*g)==typeid(Polygon)) checkValid((Polygon*)g);
        else if (typeid(*g)==typeid(MultiPolygon)) checkValid((MultiPolygon*)g);
        else if ((gc=dynamic_cast<const GeometryCollection *>(g)))
                checkValid(gc);
        else throw util::UnsupportedOperationException();
+       isChecked=true;
  }

  /*
   * Checks validity of a Point.
   */


Thanks,
Denise
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geos-devel/attachments/20081023/cf4dbdbb/attachment.html


More information about the geos-devel mailing list