]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: eh_globals: gthreads: reset _S_init before deleting key
authorAlexandre Oliva <oliva@adacore.com>
Wed, 22 Jun 2022 02:11:02 +0000 (23:11 -0300)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 19 Oct 2022 20:29:05 +0000 (21:29 +0100)
Clear __eh_globals_init's _S_init in the dtor before deleting the
gthread key.

This ensures that, in case any code involved in deleting the key
interacts with eh_globals, the key that is being deleted won't be
used, and the non-thread-specific eh_globals fallback will.

for  libstdc++-v3/ChangeLog

* libsupc++/eh_globals.cc [!_GLIBCXX_HAVE_TLS]
(__eh_globals_init::~__eh_globals_init): Clear _S_init first.

(cherry picked from commit a33dda016e5acf9c6325ce8a72a1b0238130374e)

libstdc++-v3/libsupc++/eh_globals.cc

index 768425c0f407af9065f4883c4b4a67158967be10..0aadb692a962516f037a5080ef36dfb17f9cd3ea 100644 (file)
@@ -119,8 +119,13 @@ struct __eh_globals_init
   ~__eh_globals_init()
   {
     if (_S_init)
-      __gthread_key_delete(_M_key);
-    _S_init = false;
+      {
+       /* Set it before the call, so that, should
+          __gthread_key_delete throw an exception, it won't rely on
+          the key being deleted.  */
+       _S_init = false;
+       __gthread_key_delete(_M_key);
+      }
   }
 
   __eh_globals_init(const __eh_globals_init&) = delete;