From: Jason Merrill Date: Mon, 22 Jul 2013 19:43:27 +0000 (-0400) Subject: re PR libstdc++/57914 (Memory leak in __cxa_thread_atexit when using thread_local) X-Git-Tag: releases/gcc-4.9.0~4897 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=16a1d8fe2955c301ae61a13c4cbf8bd2c83d17f0;p=thirdparty%2Fgcc.git re PR libstdc++/57914 (Memory leak in __cxa_thread_atexit when using thread_local) PR libstdc++/57914 * libsupc++/atexit_thread.cc (run): Delete cleanup elts. From-SVN: r201146 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cd87d9484872..879fd617aebb 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2013-07-22 Jason Merrill + + PR libstdc++/57914 + * libsupc++/atexit_thread.cc (run): Delete cleanup elts. + 2013-07-22 Paolo Carlini PR c++/57920 diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc index 3b33df233e81..11f1dbdeac4a 100644 --- a/libstdc++-v3/libsupc++/atexit_thread.cc +++ b/libstdc++-v3/libsupc++/atexit_thread.cc @@ -58,8 +58,13 @@ namespace { void run (void *p) { elt *e = static_cast(p); - for (; e; e = e->next) - e->destructor (e->object); + while (e) + { + elt *old_e = e; + e->destructor (e->object); + e = e->next; + delete (old_e); + } } // Run the stack of cleanups for the current thread. @@ -67,9 +72,15 @@ namespace { { void *e; if (__gthread_active_p ()) - e = __gthread_getspecific (key); + { + e = __gthread_getspecific (key); + __gthread_setspecific (key, NULL); + } else - e = single_thread; + { + e = single_thread; + single_thread = NULL; + } run (e); }