From f093122cb067a241c96cfacd6a8f19ce56dd23ca Mon Sep 17 00:00:00 2001 From: Aron Helser Date: Mon, 18 Apr 2022 15:41:59 -0400 Subject: [PATCH] Fix memory leaks identified in testing. --- vtkCleaverImageToUnstructuredGridFilter.cxx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/vtkCleaverImageToUnstructuredGridFilter.cxx b/vtkCleaverImageToUnstructuredGridFilter.cxx index 7e25e21..5b3a1ee 100644 --- a/vtkCleaverImageToUnstructuredGridFilter.cxx +++ b/vtkCleaverImageToUnstructuredGridFilter.cxx @@ -490,19 +490,19 @@ int vtkCleaverImageToUnstructuredGridFilter::RequestData(vtkInformation* vtkNotU } bool simple = false; cleaver::TetMesh* bgMesh = nullptr; - cleaver::Volume* volume = new cleaver::Volume(fields); + cleaver::Volume volume(fields); cleaver::CleaverMesher mesher(simple); - mesher.setVolume(volume); + mesher.setVolume(&volume); mesher.setAlphaInit(this->Alpha); // Create the sizing field std::vector sizingField; - sizingField.push_back(cleaver::SizingFieldCreator::createSizingFieldFromVolume(volume, + sizingField.push_back(cleaver::SizingFieldCreator::createSizingFieldFromVolume(&volume, (float)(1.0 / this->RateOfChange), (float)this->SamplingRate, (float)this->FeatureScaling, (int)this->Padding, (element_sizing_method != cleaver::Constant), verbose)); // Set Sizing Field on Volume - volume->setSizingField(sizingField[0]); + volume.setSizingField(sizingField[0]); // Construct Background Mesh mesher.setConstant(false); @@ -522,7 +522,7 @@ int vtkCleaverImageToUnstructuredGridFilter::RequestData(vtkInformation* vtkNotU // Strip Exterior Tets if (strip_exterior) { - cleaver::stripExteriorTets(mesh, volume, verbose); + cleaver::stripExteriorTets(mesh, &volume, verbose); } // Compute Quality If Havn't Already @@ -541,6 +541,13 @@ int vtkCleaverImageToUnstructuredGridFilter::RequestData(vtkInformation* vtkNotU // mesh->writeInfo(output_path + output_name, verbose); fillUnstructuredGrid(output, mesh); + // clean up memory + for(auto* field: fields) + { + delete dynamic_cast(field)->data(); + delete field; + } + return 1; }