From 3a0932f578fa89112acb456c23671dcd260cfd27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 8 Feb 2013 00:25:20 +0100 Subject: [PATCH 1/4] Fix the memory leak in minkowski_sum_3 Gaussian_map allocates a Sphere_map on every construction and passes it off to its base class SM_decorator. The decorator has a shallow copy-constructor and doesn't clean up its resource. The best fix would be to use a shared_ptr for psm_ in SM_decorator, but that possibly breaks users and classes that actually account for the missing memory management. This is the worst of all possible fixes. We just clean up all pointers. The code now checks fine with gperftools and HEAPCHECK=strict --- .../bipartite_nary_union_sorted_combined.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Minkowski_sum_3/include/CGAL/Minkowski_sum_3/bipartite_nary_union_sorted_combined.h b/Minkowski_sum_3/include/CGAL/Minkowski_sum_3/bipartite_nary_union_sorted_combined.h index d9500a27921..4f156d05be8 100644 --- a/Minkowski_sum_3/include/CGAL/Minkowski_sum_3/bipartite_nary_union_sorted_combined.h +++ b/Minkowski_sum_3/include/CGAL/Minkowski_sum_3/bipartite_nary_union_sorted_combined.h @@ -220,6 +220,16 @@ bipartite_nary_union_sorted_combined(Nef_polyhedron& N0, Ntmp.delegate(Convertor, true); CGAL_assertion(Ntmp.is_valid()); nary_union.add_polyhedron(Ntmp); + delete GcG.sphere_map(); + } + + // clean up the spherical_mapS + for(GM_iterator it = GM0.begin(); it != GM0.end(); ++it) { + delete it->first.sphere_map(); + } + + for(GM_iterator it = GM1.begin(); it != GM1.end(); ++it) { + delete it->first.sphere_map(); } return nary_union.get_union(); From b9efb884ee0a2099437a1746c13c2a34a5b37444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 8 Feb 2013 00:27:01 +0100 Subject: [PATCH 2/4] The leak in this test has to be fixed separately The test is not even using the minkowski_sum_3 function, so we have to handle Gaussian_map manually. --- .../test/Minkowski_sum_3/gaussian_map_conversion.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Minkowski_sum_3/test/Minkowski_sum_3/gaussian_map_conversion.cpp b/Minkowski_sum_3/test/Minkowski_sum_3/gaussian_map_conversion.cpp index c20d01fe53d..05754b5608a 100644 --- a/Minkowski_sum_3/test/Minkowski_sum_3/gaussian_map_conversion.cpp +++ b/Minkowski_sum_3/test/Minkowski_sum_3/gaussian_map_conversion.cpp @@ -40,6 +40,7 @@ void test_convex_parts(Nef_polyhedron_3& N) CGAL_assertion(tmp1.is_valid()); CGAL_assertion(tmp1.closure().symmetric_difference(tmp0).is_empty()); + delete G.sphere_map(); } } @@ -60,6 +61,9 @@ void test_convex_parts(Nef_polyhedron_3& N) CGAL_assertion(tmp.vertices_begin()->mark()); CGAL_assertion(!tmp.volumes_begin()->mark()); CGAL_assertion(tmp.vertices_begin()->point() == vi->point()); + + delete G.sphere_map(); + std::cerr << "single vertex " << std::endl; } } @@ -85,6 +89,8 @@ void test_convex_parts(Nef_polyhedron_3& N) eci->source()->point() || tmp.vertices_begin()->point() == eci->twin()->source()->point()); + delete G.sphere_map(); + std::cerr << "single edge " << std::endl; } @@ -106,6 +112,8 @@ void test_convex_parts(Nef_polyhedron_3& N) CGAL_assertion(!tmp.volumes_begin()->mark()); CGAL_assertion(tmp.halffacets_begin()->plane() == fci->plane() || tmp.halffacets_begin()->plane() == fci->twin()->plane()); + delete G.sphere_map(); + std::cerr << "single facet " << std::endl; } } From 3ee98b11eab89d1eec0eb017efcce3357ff3ed47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 8 Feb 2013 00:27:48 +0100 Subject: [PATCH 3/4] Leave a warning to the next person that comes across this --- Nef_S2/include/CGAL/Nef_S2/SM_decorator.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Nef_S2/include/CGAL/Nef_S2/SM_decorator.h b/Nef_S2/include/CGAL/Nef_S2/SM_decorator.h index 7f418b32a75..e1553a3ef5a 100644 --- a/Nef_S2/include/CGAL/Nef_S2/SM_decorator.h +++ b/Nef_S2/include/CGAL/Nef_S2/SM_decorator.h @@ -125,6 +125,9 @@ handles |SVertex_handle|, |SHalfedge_handle|, or |SHalfloop_handle|.}*/ protected: + // don't change this into a shared_ptr even if it seems sensible. + // minkowski_sum_3 already has a fix in place that deletes the + // object psm_ points to. Map* psm_; public: From 4632288a1f75d83a3a1d486bd5aa1ffa246c808a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 15 Feb 2013 18:50:42 +0100 Subject: [PATCH 4/4] Add the memory leak fix to changes.html --- Installation/changes.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Installation/changes.html b/Installation/changes.html index 8e4ecc704e0..eb827bb799d 100644 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -132,6 +132,11 @@ David A. Wheeler's 'SLOCCount', restricted to the include/CGAL/ +

3D Minkowski Sum of Polyhedra

+
    +
  • Fix a memory leak. +
+

3D Fast Intersection and Distance Computation

  • Update requirements of the concepts AABBTraits and AABBGeomTraits to match the implementation of the package.