[vtk-developers] vtkDataArrayTemplate.cxx writes out of bounds when malloc fails

Sean McBride sean at rogue-research.com
Fri Jun 20 16:12:35 EDT 2008

On 6/20/08 10:42 AM, Utkarsh Ayachit said:

>The nice thing about realloc is that even when the memory grows, it may 
>not result in any memory moves. In the new "new" implementation a resize 
>always needs atleast twice as much memory available. With realloc, if 
>the original memptr is already at the end of the heap (for example), 
>then realloc will simply "grow" the data block allocated, without 
>"moving" the block at all -- hence no copy incurred. Which also makes it 
>possible to grow the array to a larger size than possible with 
>"new|copy|delete" for a given system.

I redid our tests that started the other thread "vtkImageConvolve
crashes when malloc fails".  I can confirm that when we see crashes
there, we do indeed pass through this Mac-only case of using malloc/
memcpy/free instead of realloc.  So indeed OS X's crappy realloc is
exacerbating our problem.

OTOH, I'd very much like to see a patch like Burlen's so that at least
VTK does not crash.  Since I can repro such a crash easily, my next step
will be to try Burlen's patch....

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 vtk-developers mailing list