Call the registered exit functions if the dll is unloaded.
Modified: trunk/reactos/lib/crt/stdlib/_exit.c
Modified: trunk/reactos/lib/crt/stdlib/atexit.c
Modified: trunk/reactos/lib/crtdll/dllmain.c
Modified: trunk/reactos/lib/msvcrt/dllmain.c

Modified: trunk/reactos/lib/crt/stdlib/_exit.c
--- trunk/reactos/lib/crt/stdlib/_exit.c	2005-08-11 19:11:17 UTC (rev 17293)
+++ trunk/reactos/lib/crt/stdlib/_exit.c	2005-08-11 19:32:02 UTC (rev 17294)
@@ -12,13 +12,7 @@
 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();

Modified: trunk/reactos/lib/crt/stdlib/atexit.c
--- trunk/reactos/lib/crt/stdlib/atexit.c	2005-08-11 19:11:17 UTC (rev 17293)
+++ trunk/reactos/lib/crt/stdlib/atexit.c	2005-08-11 19:32:02 UTC (rev 17294)
@@ -2,6 +2,19 @@
 #include <stdlib.h>
 #include <internal/atexit.h>
 
+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
  *

Modified: trunk/reactos/lib/crtdll/dllmain.c
--- trunk/reactos/lib/crtdll/dllmain.c	2005-08-11 19:11:17 UTC (rev 17293)
+++ trunk/reactos/lib/crtdll/dllmain.c	2005-08-11 19:32:02 UTC (rev 17294)
@@ -38,6 +38,7 @@
 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 @@
         DPRINT("Detach %d\n", nAttachCount);
         /* FIXME: more cleanup... */
         _fcloseall();
+        _atexit_cleanup();
 
         /* destroy tls stuff */
         DestroyThreadData();

Modified: trunk/reactos/lib/msvcrt/dllmain.c
--- trunk/reactos/lib/msvcrt/dllmain.c	2005-08-11 19:11:17 UTC (rev 17293)
+++ trunk/reactos/lib/msvcrt/dllmain.c	2005-08-11 19:32:02 UTC (rev 17294)
@@ -37,6 +37,7 @@
 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 @@
         //DPRINT("Detach\n");
         /* FIXME: more cleanup... */
         _fcloseall();
+        _atexit_cleanup();
 
         /* destroy tls stuff */
         DestroyThreadData();