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] 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();