Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks identified in testing. #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions vtkCleaverImageToUnstructuredGridFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<cleaver::AbstractScalarField*> 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);
Expand All @@ -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
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field pointers in this vector are new'ed up manually in both segmentationToIndicatorFunctions and loadIndicatorFunctions--why can't these functions return vectors of unique_ptrs themselves? That's your code, not the cleaver API.

{
delete dynamic_cast<cleaver::FloatField *>(field)->data();
delete field;
}

return 1;
}

Expand Down