[geos-devel] [GEOS] #830: Possible memory leak in WKTReader with partial MULTIPOLYGON

GEOS geos-trac at osgeo.org
Wed Apr 12 06:09:41 PDT 2017


#830: Possible memory leak in WKTReader with partial MULTIPOLYGON
-------------------------+---------------------------
 Reporter:  goatbar      |       Owner:  geos-devel@…
     Type:  defect       |      Status:  new
 Priority:  minor        |   Milestone:
Component:  Default      |     Version:  3.5.0
 Severity:  Unassigned   |  Resolution:
 Keywords:  wkt fuzzing  |
-------------------------+---------------------------

Comment (by mloskot):

 Kurt, this is classic lack of RAII in GEOS which. Switch to C++11 should
 help, replacing auto_ptr with unique_ptr and using unique_ptr in as many
 places as possible.

 In this particular case, `vector<Geometry *> *polygons=new vector<Geometry
 *>(` could be replaced with intermediate vector on stack, once fully
 created, allocate new on heap and move `polygons` data into it before
 passing to `createMultiPolygon`.

 This however is partial fix: it will avoid leaking `polygons = new
 vector<Geometry *>` but won't avoid leaking heap-allocated items of
 `polygons`.

 Long term solution could be switching away from heap-allocated vectors to
 use of rvalues with move semantic.

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


More information about the geos-devel mailing list