[vtk-developers] vtkImageConvolve crashes when malloc fails

Amy Squillacote ahs at cfdrc.com
Tue Jun 3 16:51:22 EDT 2008


Additionally, I don't think malloc is guaranteed to return NULL when it 
fails to allocate memory (although in many implementations, that is what 
it does), so adding such checks into VTK wouldn't necessarily work 
everywhere.

- Amy

Berk Geveci wrote:
> If memory allocation fails, you will run into a crash sooner or later
> unfortunately. Even if you were to add such a check, somewhere down
> the pipeline some other class is going to die. IMHO, the only
> "graceful" way of handling this is to throw an exception that the
> application catches. Then it would have to report an error and shut
> down. Adding bunch of if statements for an exceptional case is
> probably not a good idea.
>
> -berk
>
> 2008/6/3 Mathieu Coursolle <mcoursolle at rogue-research.com>:
>   
>> Hi VTK developers,
>> I am performing a series of filters, where some of them are
>> vtkImageConvolve.
>> My input vtkImageData is usually close to 100Mbytes, and the execution of my
>> pipeline
>> seems to cause some memory fragmentation. Therefore, malloc will eventually
>> fail, causing
>> a crash in vtkImageConvolve.
>> If malloc fails during the execution of a pipeline, then the scalarPointer
>> of the resulting vtkImageData is NULL. If a connected vtkImageConvolve
>> filter receives such a vtkImageData
>> as its input, it tries to access the scalar pointer (which is NULL), causing
>> a crash.
>> A solution would be to check the pointers:
>>   // ADDED CODE BEGIN--------
>>   // Make sure the scalar pointers are valid.
>>   if (!inData[0][0]->GetScalarPointer() || !outData[0]->GetScalarPointer())
>>     {
>> vtkErrorMacro(<< "Execute: input and/or output image does not have any
>> scalar value.");
>>     return;
>>     }
>>   // ADDED CODE END--------
>>
>>
>>
>>   switch (inData[0][0]->GetScalarType())
>>     {
>>     vtkTemplateMacro(
>>       vtkImageConvolveExecute(this, inData[0][0],
>>                               static_cast<VTK_TT *>(inPtr), outData[0],
>>                               static_cast<VTK_TT *>(outPtr),
>>                               outExt, id, inInfo));
>>     default:
>>       vtkErrorMacro(<< "Execute: Unknown ScalarType");
>>       return;
>>     }
>> So I was wondering,
>> 1) Is that the right way to avoid such crashes?
>> 2) I guess that problem might occur with other filters as well...
>> Thanks.
>> Mathieu
>>
>> _______________________________________________
>> vtk-developers mailing list
>> vtk-developers at vtk.org
>> http://www.vtk.org/mailman/listinfo/vtk-developers
>>
>>
>>     
> _______________________________________________
> vtk-developers mailing list
> vtk-developers at vtk.org
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>   

-- 
Amy Squillacote                    Phone: (256) 726-4839
Computer Scientist                 Fax: (256) 726-4806
CFD Research Corporation           Web: http://www.cfdrc.com
215 Wynn Drive, Suite 501
Huntsville, AL  35805





More information about the vtk-developers mailing list