[Insight-users] possible mismatched free()/delete/delete[] ?

Luis Ibanez luis.ibanez at kitware.com
Fri, 09 Apr 2004 18:03:27 -0400


Hi Feng,

This is an interesting report.

By looking at the code, there are no uses of malloc()
in ITK, except for the

     itkBalloonForceFilter.txx

and

     itkBinaryMask3DMeshSource.txx

classes.


The Watershed is using a custom allocator
passed to the itk_hash_map class, but it
uses "new".

 From your email, I understand that Valgrind only
flags this when you link with ITK shared libraries
and not when you link with ITK Static libraries.

Is that correct ?


    Thanks


       Luis


-----------------
Feng Ma wrote:

> Hi,
> 
>  I met the "Mismatched free() / delete / delete []" in valgrind output 
> of my code:
> 
>  watershed = itk::WatershedImageFilter<InternalImageType>::New();
>  watershed->SetThreshold(lowerThreshold);
>  watershed->SetLevel(maxFloodLevel);
>  watershed->SetInput(magnitude->GetOutput());
>  watershed->UpdateLargestPossibleRegion();
> 
>  The valgrind output is:
> 
> ==22333==
> ==22333== Mismatched free() / delete / delete []
> ==22333==    at 0x40027C07: __builtin_delete (vg_replace_malloc.c:233)
> ==22333==    by 0x40B8718F: 
> itk::EquivalencyTable::~EquivalencyTable(void) (in 
> /usr/lib/InsightToolkit/libITKCommon.so)
> ==22333==    by 0x40B90A0E: itk::LightObject::UnRegister(void) const (in 
> /usr/lib/InsightToolkit/libITKCommon.so)
> ==22333==    by 0x40B97B40: itk::Object::UnRegister(void) const (in 
> /usr/lib/InsightToolkit/libITKCommon.so)
> ==22333==    Address 0x469E2F14 is 0 bytes inside a block of size 92 
> alloc'd
> ==22333==    at 0x40027894: malloc (vg_replace_malloc.c:153)
> ==22333==    by 0x822466C: __builtin_new (in /home/fma/test/main)
> ==22333==    by 0x81CAC98: itk::EquivalencyTable::New(void) 
> (/usr/include/InsightToolkit/Common/itkEquivalencyTable.h:55)
> ==22333==    by 0x81B34A9: itk::watershed::Segmenter<itk::Image<float, 
> 3> >::LabelMinima(itk::SmartPointer<itk::Image<float, 3> >, 
> itk::ImageRegion<3>, itk::hash_map<unsigned long, 
> itk::watershed::Segmenter<itk::Image<float, 3> >::flat_region_t, 
> itk::hash<unsigned long>, equal_to<unsigned long>, allocator<char> > &, 
> float) 
> (/usr/include/InsightToolkit/Algorithms/itkWatershedSegmenter.txx:636)
> 
>  I know that itkNewMacro() use new operator. But somehow, it eventually 
> ends up with malloc().
> I am using ITK1.4.0. The ITK libraries were dynamic libraries.
> 
>  Interesting thing is: I have another project with same code and ITK 
> compiled as static libraries, I didn't see this error.
> 
>  Any hints?
> 
>  Thanks a lot.
> 
> -Feng
> 
> _________________________________________________________________
> FREE pop-up blocking with the new MSN Toolbar – get it now! 
> http://clk.atdmt.com/AVE/go/onm00200415ave/direct/01/
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>