public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/18185] New: Unhandled exceptions leak
@ 2004-10-27 18:02 velco at fadata dot bg
  2004-10-27 20:29 ` [Bug libstdc++/18185] " velco at fadata dot bg
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: velco at fadata dot bg @ 2004-10-27 18:02 UTC (permalink / raw)
  To: gcc-bugs

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.

-- 
           Summary: Unhandled exceptions leak
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: velco at fadata dot bg
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18185


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-11-08 18:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-27 18:02 [Bug libstdc++/18185] New: Unhandled exceptions leak velco at fadata dot bg
2004-10-27 20:29 ` [Bug libstdc++/18185] " velco at fadata dot bg
2004-10-28  4:13 ` pinskia at gcc dot gnu dot org
2004-11-01 22:31 ` bkoz at gcc dot gnu dot org
2004-11-01 22:47 ` cvs-commit at gcc dot gnu dot org
2004-11-08 17:41 ` [Bug libstdc++/18185] [3.4 only] " cvs-commit at gcc dot gnu dot org
2004-11-08 18:05 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).