[ITK-dev] linear interpolator leaks?

Luc Hermitte luc.hermitte at c-s.fr
Wed Jun 1 05:02:07 EDT 2016


Hi,
Le 01/06/2016 à 09:45, M.Staring at lumc.nl a écrit :
> I noticed that our valgrind build of elastix has reports like this:
> 
> *UMR*==5253== Invalid read of size 2
> 
> ==5253==    at 0x552241:
> itk::LinearInterpolateImageFunction<itk::Image<short, 2u>,
> double>::EvaluateOptimized(itk::LinearInterpolateImageFunction<itk::Image<short,
> 2u>, double>::Dispatch<2u> const&, itk::ContinuousIndex<double, 2u>
> const&) const (itkLinearInterpolateImageFunction.h:173)
> 
> ==5253==    by 0x54976C:
> itk::LinearInterpolateImageFunction<itk::Image<short, 2u>,
> double>::EvaluateAtContinuousIndex(itk::ContinuousIndex<double, 2u>
> const&) const (itkLinearInterpolateImageFunction.h:99)
> 
> ==5253==    by 0x54397B: bool TestInterpolators<2u>()
> (itkAdvancedLinearInterpolatorTest.cxx:171)
> 
> ==5253==    by 0x53E232: main (itkAdvancedLinearInterpolatorTest.cxx:279)
> 
> ==5253==  Address 0x6822b94 is 52 bytes inside a block of size 83 free'd
> 
> ==5253==    at 0x4C2C2BC: operator delete(void*) (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> 
> ==5253==    by 0x5ED884: itk::ObjectFactoryBase::CreateObject(char
> const*) (in
> /home/marius/nightly-builds/elastix/bin_debug/bin/itkAdvancedLinearInterpolatorTest)
> 
> ==5253==    by 0x5EF91B: itk::ObjectFactoryBase::CreateInstance(char
> const*) (in
> /home/marius/nightly-builds/elastix/bin_debug/bin/itkAdvancedLinearInterpolatorTest)
> 
> ==5253==    by 0x550335:
> itk::ObjectFactory<itk::LinearInterpolateImageFunction<itk::Image<short,
> 2u>, double> >::Create() (itkObjectFactory.h:60)
> 
> ==5253==    by 0x548A90:
> itk::LinearInterpolateImageFunction<itk::Image<short, 2u>,
> double>::New() (in
> /home/marius/nightly-builds/elastix/bin_debug/bin/itkAdvancedLinearInterpolatorTest)
> 
> ==5253==    by 0x543540: bool TestInterpolators<2u>()
> (itkAdvancedLinearInterpolatorTest.cxx:114)
> 
> ==5253==    by 0x53E232: main (itkAdvancedLinearInterpolatorTest.cxx:279)
> 
> ==5253==
> 
>  
> 
> On inspection these lines in itk LinearInterpolateImageFunction.h seem
> troublesome:
> 
>  
> 
> const RealType & val000 = inputImagePtr->GetPixel(basei);
> 
> 
> Note that a real type is obtained by reference from a function that
> often does not return  a real type. Is this allowed?

It should be fine. We are authorized to get a const reference to the
result of a function that returns by value.
Most of the time, it's never done because this is quite odd. As long as
the function doesn't return a reference/address to a local variable,
there is no problem. Have you checked without the "const&" ?

Any way, this won't cause a leak. We could have suspected a dangling
reference, but there should be none IIRC this part of the code.
See
https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/

I'd check whether the index produced in within the boundaries on the
internal buffer with a `assert(offset < m_Buffer->Size());` in
itk::Image::GetPixel.

I'd be curious to see what clang address sanatizer says (it may give
more information than valgrind -- like where the free'd address was
allocated then free'd)

Regards

-- 
Luc Hermitte


More information about the Insight-developers mailing list