summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/dcrt0.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/dcrt0.cc')
-rw-r--r--winsup/cygwin/dcrt0.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index c5db62c07..b24e5fe16 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -129,9 +129,11 @@ char title_buf[TITLESIZE + 1];
static void
do_global_dtors (void)
{
- if (user_data->dtors)
+ dll_global_dtors ();
+ void (**pfunc) () = user_data->dtors;
+ if (pfunc)
{
- void (**pfunc)() = user_data->dtors;
+ user_data->dtors = NULL;
while (*++pfunc)
(*pfunc) ();
}
@@ -972,7 +974,6 @@ extern "C" void
__main (void)
{
do_global_ctors (user_data->ctors, false);
- atexit (do_global_dtors);
}
exit_states NO_COPY exit_state;
@@ -994,6 +995,8 @@ do_exit (int status)
EnterCriticalSection (&exit_lock);
muto::set_exiting_thread ();
+ do_global_dtors ();
+
if (exit_state < ES_EVENTS_TERMINATE)
{
exit_state = ES_EVENTS_TERMINATE;
@@ -1096,6 +1099,7 @@ cygwin_atexit (void (*function)(void))
extern "C" void
cygwin_exit (int n)
{
+ do_global_dtors ();
if (atexit_lock)
atexit_lock.acquire ();
exit (n);