GCC Bugzilla Bug 24025
Howard Hinnant
hhinnant@apple.com
Fri Nov 4 01:27:00 GMT 2005
I was having a look at http://gcc.gnu.org/bugzilla/show_bug.cgi?
id=24025 which involves what happens when the first exception thrown
in an application is bad_alloc. There's a point in eh_globals.cc :
__cxa_get_globals which tries to malloc memory and calls terminate()
if the malloc fails. I'm not an expert in this area but here's what
it looks like to me (comments asked for!):
During __cxa_get_globals there are several possible failure modes.
At each point, on failure a pointer to a "backup" __cxa_eh_globals if
a thread-local version is not obtained. That strategy is followed
consistently until the bottom of the routine where suddenly failure
to allocate a __cxa_eh_globals leads to termination. I am wondering
if simply returning a pointer to the "backup" __cxa_eh_globals would
not be a better course of action.
Here is the proposed patch:
Index: libstdc++-v3/libsupc++/eh_globals.cc
===================================================================
--- libstdc++-v3/libsupc++/eh_globals.cc (revision 106370)
+++ libstdc++-v3/libsupc++/eh_globals.cc (working copy)
@@ -115,7 +115,10 @@
if ((g = (__cxa_eh_globals *)
std::malloc (sizeof (__cxa_eh_globals))) == 0
|| __gthread_setspecific (globals_key, (void *) g) != 0)
- std::terminate ();
+ {
+ std::free(g);
+ return &globals_static;
+ }
g->caughtExceptions = 0;
g->uncaughtExceptions = 0;
}
Comments?
Thanks,
Howard
PS: I'm still learning process here. So if I'm not doing it right,
please let me know.
More information about the Libstdc++
mailing list