[Insight-developers] Mismatched new - free (freeing images in VTK created by ITK)

Sean McBride sean at rogue-research.com
Fri Aug 24 17:15:16 EDT 2007


On 8/23/07 12:48 PM, Karthik Krishnan said:

>An itk::VectorImage is passed through as a vtkImageData grabbing the
>internal pointer.
>
>Valgrind is groaning about mismatching a new with a free.  The issue is that
>ITK images (see itk::ImportImageContainer) allocate/deallocate memory with
>"new/delete".  VTK images (see vtkDataArrayTemplate) free memory with
>"malloc/free". Google tells me that you may be able to get away with this on
>some platforms, but it is not guarenteed to work.
>
>Is there a solution to this or should I just be ignoring this ?

Well, since no one else has said anything.... It seems to me you have
found a hard-to-find bug/design flaw, I would definitely fix it!

I don't know that code, so I don't have many useful suggestions.  But
why is one class deleting memory alloced by another?  Why is
itk::VectorImage caching a private internal pointer?  Maybe copy it
instead?  Maybe increase the vtkImageData object's ref count?

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada




More information about the Insight-developers mailing list