https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113401
--- Comment #5 from Iain Sandoe <iains at gcc dot gnu.org> --- (In reply to Florian Weimer from comment #4) > (In reply to Iain Sandoe from comment #3) > > for platforms using pthreads as the underlying resource, then perhaps we can > > do this without thread_atexit (which I do not see in many places) by using > > pthread_cleanup_push () > > The current implementation already uses the same underlying mechanism as > pthread_cleanup_push if building with -fexceptions. It does not solve the > leak because the outermost handler deliberately does not perform a full > deallocation of the thread state. hmm.. I'm slightly confused here. We certainly make the __gcc_nested_func_ptr_deleted () call a cleanup attached to scope exits and certainly the last page of trampolines is not deallocated (as you note for the sake of avoiding churn in m-mapping). However, in the current code the only pthread-specific stuff I see (in, say config/i386/heap-trampoline.c) is specific to changing protections on the mapped pages. What I was thinking of is attaching a thread exit cleanup using pthread_cleanup_push() for platforms with pthreads but without Libc support for _thread_atexit - I guess I'm missing something :)