Skip to content

Commit 9a431cc

Browse files
committed
BUG: Address RunLengthTextureFeatures histogram memory leak
1 parent a23987b commit 9a431cc

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

include/itkRunLengthTextureFeaturesImageFilter.hxx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
171171
// Declaration of the variables useful to iterate over the all the offsets
172172
OffsetType offset;
173173
unsigned int totalNumberOfRuns;
174-
unsigned int **hist = new unsigned int*[m_NumberOfBinsPerAxis];
175-
for(unsigned int a= 0; a < m_NumberOfBinsPerAxis; a++)
174+
unsigned int **histogram = new unsigned int*[m_NumberOfBinsPerAxis];
175+
for(unsigned int axis = 0; axis < m_NumberOfBinsPerAxis; ++axis)
176176
{
177-
hist[a] = new unsigned int[m_NumberOfBinsPerAxis];
177+
histogram[axis] = new unsigned int[m_NumberOfBinsPerAxis];
178178
}
179179

180180
// Declaration of the variables useful to iterate over the all neighborhood region
@@ -210,7 +210,7 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
210210
{
211211
for(unsigned int b = 0; b < m_NumberOfBinsPerAxis; b++)
212212
{
213-
hist[a][b] = 0;
213+
histogram[a][b] = 0;
214214
}
215215
}
216216
totalNumberOfRuns = 0;
@@ -266,20 +266,26 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
266266
}
267267
}
268268
// Increase the corresponding bin in the histogram
269-
this->IncreaseHistogram(hist, totalNumberOfRuns,
269+
this->IncreaseHistogram(histogram, totalNumberOfRuns,
270270
curentInNeighborhoodPixelIntensity,
271271
offset, pixelDistance);
272272
}
273273
}
274274
// Compute the run length features
275-
this->ComputeFeatures( hist, totalNumberOfRuns, outputPixel);
275+
this->ComputeFeatures( histogram, totalNumberOfRuns, outputPixel);
276276
outputIt.Set(outputPixel);
277277

278278
progress.CompletedPixel();
279279
++inputNIt;
280280
++outputIt;
281281
}
282282
}
283+
284+
for(unsigned int axis = 0; axis < m_NumberOfBinsPerAxis; ++axis)
285+
{
286+
delete histogram[axis];
287+
}
288+
delete histogram;
283289
}
284290

285291
template<typename TInputImage, typename TOutputImage>
@@ -389,7 +395,7 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
389395
template<typename TInputImage, typename TOutputImage>
390396
void
391397
RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
392-
::IncreaseHistogram(unsigned int **hist, unsigned int &totalNumberOfRuns,
398+
::IncreaseHistogram(unsigned int **histogram, unsigned int &totalNumberOfRuns,
393399
const PixelType &curentInNeighborhoodPixelIntensity,
394400
const OffsetType &offset, const unsigned int &pixelDistance)
395401
{
@@ -406,14 +412,14 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
406412
if (offsetDistanceBin < static_cast< int >( m_NumberOfBinsPerAxis ))
407413
{
408414
totalNumberOfRuns++;
409-
hist[curentInNeighborhoodPixelIntensity][offsetDistanceBin]++;
415+
histogram[curentInNeighborhoodPixelIntensity][offsetDistanceBin]++;
410416
}
411417
}
412418

413419
template<typename TInputImage, typename TOutputImage>
414420
void
415421
RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
416-
::ComputeFeatures( unsigned int **hist,const unsigned int &totalNumberOfRuns,
422+
::ComputeFeatures( unsigned int **histogram,const unsigned int &totalNumberOfRuns,
417423
typename TOutputImage::PixelType &outputPixel)
418424
{
419425
OutputRealType shortRunEmphasis = NumericTraits<OutputRealType>::ZeroValue();
@@ -436,7 +442,7 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
436442
{
437443
for(unsigned int b = 0; b < m_NumberOfBinsPerAxis; b++)
438444
{
439-
OutputRealType frequency = hist[a][b];
445+
OutputRealType frequency = histogram[a][b];
440446
if ( Math::ExactlyEquals(frequency, NumericTraits<OutputRealType>::ZeroValue()) )
441447
{
442448
continue;

0 commit comments

Comments
 (0)