Calls to malloc during an exception

Perry Smith pedz@easesoftware.net
Wed Jan 18 17:41:00 GMT 2006


In the course of doing my work last week to get exception handling  
working in my device driver, I learned that the exception processing  
code calls malloc during the exception.  This seems weak to me.  It  
seems like one of the most critical times to throw an exception is  
when malloc fails.

I did not study the code very much to see what happens if the malloc  
fails during the exception processing but I assume its not good.

It seems like a better approach would be to pre-allocate storage and  
use it during the exception handling.  The design objective, to me,  
would be to make the exception handling as bullet proof as possible.   
I understand that it is not known how many exceptions are going to  
stack up but I think taking a reasonable guess, pre-allocating that  
space, and then fall back to malloc when that space fills up would be  
much less likely to fail during a critical time.

Has this been considered?

Perry



More information about the Gcc mailing list