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

Sean McBride sean at rogue-research.com
Fri Jun 20 13:43:24 EDT 2008


On 6/20/08 10:06 AM, Burlen Loring said:

>In the current implementation, if __APPLE__ is defined then realloc is 
>*not* used.

Yikes!  The comment in code says:

  // OS X's realloc does not free memory if the new block is smaller.  This
  // is a very serious problem and causes huge amount of memory to be
  // wasted. Do not use realloc on the Mac.

I've found a discussion from 2003 on an Apple list confirming this:
<http://lists.apple.com/archives/darwin-development/2003/Mar/msg00176.html>

And we've confirmed it still behaves this way in 10.5.3.

> Arrays are always moved. From what I understand(I am not a 
>mac user) gcc defines this on mac. & gcc is mac's default compiler. I 
>assume that if not using realloc were a huge issue that mac users would 
>have complained about this? Also we have the choice of doing something like:

Perhaps we have.... :) We are seeing memory fragmentation issues with
VTK that lead to complete memory exhaustion (and eventual crash due to
malloc returning null and vtk dereferencing it anyway).  See this recent
thread:
<http://www.nabble.com/vtkImageConvolve-crashes-when-malloc-fails-
to17632665.html>

But they could be unrelated...

-- 
____________________________________________________________
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