Skip to content

Commit

Permalink
BUG: Fix ParabolicErodeDilateImageFilter progress memory leak, use stack
Browse files Browse the repository at this point in the history
Declaring `ProgressReporter` on the stack (instead of on the heap) may benefit run-time performance. But moreover, it fixes a memory leak.

- Corresponds with pull request richardbeare/parabolicMorphology#11 "BUG: Fix memory leaks by moving `progress` from the heap to the stack"
  • Loading branch information
N-Dekker committed Jul 2, 2024
1 parent 7e072fb commit d1e52fc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Common/itkParabolicErodeDilateImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ ParabolicErodeDilateImageFilter<TInputImage, doDilate, TOutputImage>::ThreadedGe
}
float progressPerDimension = 1.0 / ImageDimension;

ProgressReporter * progress = new ProgressReporter(this,
threadId,
NumberOfRows[m_CurrentDimension],
30,
m_CurrentDimension * progressPerDimension,
progressPerDimension);
ProgressReporter progress(this,
threadId,
NumberOfRows[m_CurrentDimension],
30,
m_CurrentDimension * progressPerDimension,
progressPerDimension);

using InputConstIteratorType = ImageLinearConstIteratorWithIndex<TInputImage>;
using OutputIteratorType = ImageLinearIteratorWithIndex<TOutputImage>;
Expand Down Expand Up @@ -263,7 +263,7 @@ ParabolicErodeDilateImageFilter<TInputImage, doDilate, TOutputImage>::ThreadedGe
doOneDimension<InputConstIteratorType, OutputIteratorType, RealType, OutputPixelType, doDilate>(
inputIterator,
outputIterator,
*progress,
progress,
LineLength,
0,
this->m_MagnitudeSign,
Expand Down Expand Up @@ -301,7 +301,7 @@ ParabolicErodeDilateImageFilter<TInputImage, doDilate, TOutputImage>::ThreadedGe
doOneDimension<OutputConstIteratorType, OutputIteratorType, RealType, OutputPixelType, doDilate>(
inputIteratorStage2,
outputIterator,
*progress,
progress,
LineLength,
m_CurrentDimension,
this->m_MagnitudeSign,
Expand Down

0 comments on commit d1e52fc

Please sign in to comment.