Message ID | orh74ed03m.fsf@lxoliva.fsfla.org |
---|---|
State | New |
Headers | show |
Series | libstdc++: eh_globals: gthreads: reset _S_init before deleting key | expand |
On Tue, 21 Jun 2022 at 07:04, Alexandre Oliva via Libstdc++ <libstdc++@gcc.gnu.org> wrote: > > > 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. > > Regstrapped on x86_64-linux-gnu, also tested with a cross to > aarch64-rtems6. Ok to install? OK, thanks. > PS: This is a fix for a theoretical issue, that came to mind while I > independently investigated the problem that I later found to be > PR105880. It looks like a real problem though, if rare in practice.
diff --git a/libstdc++-v3/libsupc++/eh_globals.cc b/libstdc++-v3/libsupc++/eh_globals.cc index 768425c0f407a..0aadb692a9625 100644 --- a/libstdc++-v3/libsupc++/eh_globals.cc +++ b/libstdc++-v3/libsupc++/eh_globals.cc @@ -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;