Bug #74371 Valgrind: Memory leak when doing spatial operations on geometrycollections

Submitted: 14 Oct 2014 11:32 Modified: 31 Oct 2014 15:18
Reporter: Norvald Ryeng Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: GIS Severity:S3 (Non-critical)
Version:5.7.6 OS:Any
Assigned to: CPU Architecture:Any

[14 Oct 2014 11:32] Norvald Ryeng
Description:
2,592 bytes in 16 blocks are definitely lost in loss record 47 of 49
   at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0xF40E5B: my_raw_malloc (my_malloc.c:171)
   by 0xF40AE9: my_malloc (my_malloc.c:51)
   by 0xD67713: String::mem_realloc(unsigned long) (sql_string.cc:102)
   by 0x9779CD: String::reserve(unsigned long) (sql_string.h:475)
   by 0x9E9D3B: BG_geometry_collection::store(Geometry const*) (item_geofunc.cc:3073)
   by 0x9E9C75: BG_geometry_collection::store_geometry(Geometry const*) (item_geofunc.cc:3051)
   by 0x9F69A6: BG_geometry_collection::fill(Geometry const*) (item_geofunc.h:119)
   by 0xA0B417: Geometry* Item_func_spatial_operation::geocol_intersection<double, boost::geometry::cs::cartesian>(Geometry*, Geometry*, String*, bool*) (item_geofunc.cc:7475)
   by 0xA008C0: Geometry* Item_func_spatial_operation::geometry_collection_set_operation<double, boost::geometry::cs::cartesian>(Geometry*, Geometry*, String*, bool*) (item_geofunc.cc:7401)
   by 0x9EB8CF: Item_func_spatial_operation::val_str(String*) (item_geofunc.cc:7214)
   by 0x9E5E42: Item_func_as_wkt::val_str_ascii(String*) (item_geofunc.cc:1386)
   by 0xB30EEB: Item_str_func::val_str_from_val_str_ascii(String*, String*) (item_strfunc.cc:82)
   by 0x9B450F: Item_str_ascii_func::val_str(String*) (item_strfunc.h:114)
   by 0x96E581: Item::send(Protocol*, String*) (item.cc:6941)
   by 0xB9ED87: Protocol::send_result_set_row(List<Item>*) (protocol.cc:1005)

How to repeat:
SET @a=ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON('
  '((0 0,1 0,1 1,0 1,0 0)),((1 1,10 1,10 10,1 10,1 1),'
  '(4 4,6 4,6 6,4 6,4 4))))');

SET @b=GeometryCollection(
Point(1,1),
LineString(Point(1,1),Point(2,2)),
Polygon(LineString(Point(0,0),Point(1,0),Point(1,1),
  Point(0,1),Point(0,0))),
Polygon(LineString(Point(0,0),Point(10,0),Point(10,10),
  Point(0,10),Point(0,0)),LineString(Point(4,4),Point(6,4),
  Point(6,6),Point(4,6),Point(4,4))),
MultiPoint(Point(1,1),Point(2,2)),
MultiLineString(Linestring(Point(1,1),Point(2,2)),
  LineString(Point(3,3),Point(4,4))),
MultiPolygon(Polygon(Linestring(Point(0,0),Point(1,0),
  Point(1,1),Point(0,1),Point(0,0))),
  Polygon(Linestring(Point(5,5),Point(10,5),Point(10,10),
  Point(5,10),Point(5,5)))),
MultiPolygon(Polygon(LineString(Point(0,0),Point(1,0),
  Point(1,1),Point(0,1),Point(0,0))),
  Polygon(Linestring(Point(5,5),Point(10,5),Point(10,10),
  Point(5,10),Point(5,5)),Linestring(Point(6,6),Point(7,6),
  Point(7,7),Point(6,7),Point(6,6)))),
GeometryCollection(Point(1,1)),
GeometryCollection(LineString(Point(1,1),Point(2,2))),
GeometryCollection(Polygon(LineString(Point(0,0),Point(1,0),
  Point(1,1),Point(0,1),Point(0,0)))),
GeometryCollection(Polygon(Linestring(Point(0,0),
  Point(10,0),Point(10,10),Point(0,10),Point(0,0)),
  Linestring(Point(4,4),Point(6,4),Point(6,6),Point(4,6),
  Point(4,4)))),
GeometryCollection(MultiPoint(Point(1,1),Point(2,2))),
GeometryCollection(MultiLineString(Linestring(Point(1,1),
  Point(2,2)),LineString(Point(3,3),Point(4,4)))),
GeometryCollection(MultiPolygon(Polygon(Linestring(
  Point(0,0),Point(1,0),Point(1,1),Point(0,1),Point(0,0))),
  Polygon(Linestring(Point(5,5),Point(10,5),Point(10,10),
  Point(5,10),Point(5,5))))),
GeometryCollection(MultiPolygon(Polygon(LineString(
  Point(0,0),Point(1,0),Point(1,1),Point(0,1),Point(0,0))),
  Polygon(Linestring(Point(5,5),Point(10,5),Point(10,10),
  Point(5,10),Point(5,5)),Linestring(Point(6,6),Point(7,6),
  Point(7,7),Point(6,7),Point(6,6)))))
);

SELECT AsText(ST_Intersection(@a, @b));

Suggested fix:
Don't leak.
[31 Oct 2014 15:18] Paul DuBois
Noted in 5.7.6 changelogs.

Depending on contents, geometry collection objects were not properly
destroyed, resulting in a memory leak.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.