diff --git a/reactos/lib/crt/stdlib/_exit.c b/reactos/lib/crt/stdlib/_exit.c index 0d6a1630d46..d2e3f46db19 100644 --- a/reactos/lib/crt/stdlib/_exit.c +++ b/reactos/lib/crt/stdlib/_exit.c @@ -12,13 +12,7 @@ struct __atexit *__atexit_ptr = 0; void exit(int status) { //int i; - struct __atexit *a = __atexit_ptr; - __atexit_ptr = 0; /* to prevent infinite loops */ - while (a) - { - (a->__function)(); - a = a->__next; - } + /* if (__stdio_cleanup_hook) __stdio_cleanup_hook(); diff --git a/reactos/lib/crt/stdlib/atexit.c b/reactos/lib/crt/stdlib/atexit.c index c58e534b773..d6c105c4b1f 100644 --- a/reactos/lib/crt/stdlib/atexit.c +++ b/reactos/lib/crt/stdlib/atexit.c @@ -2,6 +2,19 @@ #include #include +void _atexit_cleanup(void) +{ + struct __atexit *next, *a = __atexit_ptr; + __atexit_ptr = 0; /* to prevent infinite loops */ + while (a) + { + (a->__function)(); + next = a->__next; + free(a); + a = next; + } +} + /* * @implemented * diff --git a/reactos/lib/crtdll/dllmain.c b/reactos/lib/crtdll/dllmain.c index 98118f70f28..f1aa0a760b4 100644 --- a/reactos/lib/crtdll/dllmain.c +++ b/reactos/lib/crtdll/dllmain.c @@ -38,6 +38,7 @@ extern BOOL __fileno_init(void); extern int BlockEnvToEnvironA(void); extern int BlockEnvToEnvironW(void); extern void FreeEnvironment(char **environment); +extern void _atexit_cleanup(void); extern unsigned int _osver; extern unsigned int _winminor; @@ -174,6 +175,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) DPRINT("Detach %d\n", nAttachCount); /* FIXME: more cleanup... */ _fcloseall(); + _atexit_cleanup(); /* destroy tls stuff */ DestroyThreadData(); diff --git a/reactos/lib/msvcrt/dllmain.c b/reactos/lib/msvcrt/dllmain.c index 58b41c7aea5..4a837a1e67c 100644 --- a/reactos/lib/msvcrt/dllmain.c +++ b/reactos/lib/msvcrt/dllmain.c @@ -37,6 +37,7 @@ extern BOOL __fileno_init(void); extern int BlockEnvToEnvironA(void); extern int BlockEnvToEnvironW(void); extern void FreeEnvironment(char **environment); +extern void _atexit_cleanup(void); extern unsigned int _osver; extern unsigned int _winminor; @@ -116,6 +117,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) //DPRINT("Detach\n"); /* FIXME: more cleanup... */ _fcloseall(); + _atexit_cleanup(); /* destroy tls stuff */ DestroyThreadData();