From 2c6e9c2b70b5975827ca1b8cdf6f5a8091aa5992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Thu, 20 Dec 2018 15:57:51 +0100 Subject: [PATCH] Fixed memory leaks in partition code --- .../CGAL/boost/graph/METIS/partition_dual_graph.h | 15 ++++++++++++--- .../CGAL/boost/graph/METIS/partition_graph.h | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/METIS/partition_dual_graph.h b/BGL/include/CGAL/boost/graph/METIS/partition_dual_graph.h index 8bfeb002ae1..7e2a15870a7 100644 --- a/BGL/include/CGAL/boost/graph/METIS/partition_dual_graph.h +++ b/BGL/include/CGAL/boost/graph/METIS/partition_dual_graph.h @@ -36,12 +36,15 @@ #include #include +#include + namespace CGAL { namespace METIS { template -void partition_dual_graph(const TriangleMesh& tm, int nparts, +void partition_dual_graph(const TriangleMesh& tm, + int nparts, METIS_options options, // options array const NamedParameters& np) { @@ -93,11 +96,11 @@ void partition_dual_graph(const TriangleMesh& tm, int nparts, idx_t objval; // partition info for the nodes - idx_t* npart = (idx_t*) calloc(nn, sizeof(idx_t)); + idx_t* npart = (idx_t*) calloc(num_vertices(tm), sizeof(idx_t)); CGAL_assertion(npart != NULL); // partition info for the elements - idx_t* epart = (idx_t*) calloc(ne, sizeof(idx_t)); + idx_t* epart = (idx_t*) calloc(num_faces(tm), sizeof(idx_t)); CGAL_assertion(epart != NULL); // do not support Fortran-style arrays @@ -118,6 +121,12 @@ void partition_dual_graph(const TriangleMesh& tm, int nparts, Output_face_partition_ids fo; vo(tm, indices, npart, get_param(np, internal_np::vertex_partition_id)); fo(tm, epart, get_param(np, internal_np::face_partition_id)); + + delete[] eptr; + delete[] eind; + + std::free(npart); + std::free(epart); } template diff --git a/BGL/include/CGAL/boost/graph/METIS/partition_graph.h b/BGL/include/CGAL/boost/graph/METIS/partition_graph.h index 65176d37131..d0f3e56b759 100644 --- a/BGL/include/CGAL/boost/graph/METIS/partition_graph.h +++ b/BGL/include/CGAL/boost/graph/METIS/partition_graph.h @@ -34,6 +34,8 @@ #include #include +#include + namespace CGAL { namespace METIS { @@ -76,7 +78,8 @@ struct Output_face_partition_ids }; template -void partition_graph(const TriangleMesh& tm, int nparts, +void partition_graph(const TriangleMesh& tm, + int nparts, METIS_options options, // pointer to the options array const NamedParameters& np) { @@ -125,11 +128,11 @@ void partition_graph(const TriangleMesh& tm, int nparts, idx_t objval; // partition info for the nodes - idx_t* npart = (idx_t*) calloc(nn, sizeof(idx_t)); + idx_t* npart = (idx_t*) calloc(num_vertices(tm), sizeof(idx_t)); CGAL_assertion(npart != NULL); // partition info for the elements - idx_t* epart = (idx_t*) calloc(ne, sizeof(idx_t)); + idx_t* epart = (idx_t*) calloc(num_faces(tm), sizeof(idx_t)); CGAL_assertion(epart != NULL); // do not support Fortran-style arrays @@ -150,6 +153,12 @@ void partition_graph(const TriangleMesh& tm, int nparts, Output_face_partition_ids fo; vo(tm, indices, npart, get_param(np, internal_np::vertex_partition_id)); fo(tm, epart, get_param(np, internal_np::face_partition_id)); + + delete[] eptr; + delete[] eind; + + std::free(npart); + std::free(epart); } template