This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Unhandled exceptions leak


  When a thread is terminated from within an exception handling block,
exception object(s) (__cxa_exeption) are leaked, as the TSD destructor
for __cxa_eh_globals instance does delete them.  The following program
demonstrates the leak.  A patch and a ChangeLog entry follows.

#include <pthread.h>

static void *
foo (void *p)
{
  try
    {
      throw 0;
    }
  catch (int)
    {
      pthread_exit (0);
    }
}

int
main ()
{
  pthread_t t;
  void *p;

  pthread_create (&t, 0, foo, 0);
  pthread_join (t, &p);
  return 0;
}


--- /home/velco/src/gcc-4.0/libstdc++-v3/libsupc++/eh_globals.cc.~1.6.~ Tue Aug 3 09:45:54 2004
+++ /home/velco/src/gcc-4.0/libstdc++-v3/libsupc++/eh_globals.cc Wed Oct 27 20:50:17 2004
@@ -48,7 +48,19 @@
get_globals_dtor (void *ptr)
{
if (ptr)
- std::free (ptr);
+ {
+ __cxa_exception *exn, *next;
+
+ exn = ((__cxa_eh_globals *) ptr)->caughtExceptions;
+ while (exn)
+ {
+ next = exn->nextException;
+ _Unwind_DeleteException (&exn->unwindHeader);
+ exn = next;
+ }
+
+ std::free (ptr);
+ }
}


static void

2004-10-27 Momchil Velikov <velco@fadata.bg>

	* libsupc++/eh_globals.cc (get_globals_dtor): Delete unhandled
	exceptions.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]