This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Calls to malloc during an exception
- From: Mike Stump <mrs at apple dot com>
- To: Perry Smith <pedz at easesoftware dot net>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Wed, 18 Jan 2006 19:32:53 -0800
- Subject: Re: Calls to malloc during an exception
- References: <CEE3015A-6958-4D8E-970C-E4C1164BA72F@easesoftware.net>
On Jan 18, 2006, at 9:41 AM, Perry Smith wrote:
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.
You'll want to read the code. Last I knew, there was a fallback
buffer that is used to allocate from when malloc fails, just so you
can throw on memory failure. You can retune to have any size
fallback buffer you want, but once it is gone, you die.
Also, be sure to throw and catch one exception up front if you care
deeply about things working well. This preallocates things and gets
things hot so that the chances of dying later are reduced.
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 was good, with some luck, it still is.
It seems like a better approach would be to pre-allocate storage
and use it during the exception handling.
No need to use the preallocated area if malloc is going to work for you.
Has this been considered?
Yes.