diff --git a/reactos/lib/msvcrt/misc/dllmain.c b/reactos/lib/msvcrt/misc/dllmain.c index a00c0afb46c..fb7d6804bf1 100644 --- a/reactos/lib/msvcrt/misc/dllmain.c +++ b/reactos/lib/msvcrt/misc/dllmain.c @@ -1,4 +1,4 @@ -/* $Id: dllmain.c,v 1.17 2002/11/24 18:42:23 robd Exp $ +/* $Id: dllmain.c,v 1.18 2003/04/24 16:34:26 hbirr Exp $ * * dllmain.c * @@ -14,9 +14,9 @@ * DISCLAMED. This includes but is not limited to warrenties of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * $Revision: 1.17 $ - * $Author: robd $ - * $Date: 2002/11/24 18:42:23 $ + * $Revision: 1.18 $ + * $Author: hbirr $ + * $Date: 2003/04/24 16:34:26 $ * */ @@ -42,6 +42,7 @@ extern unsigned int _winver; extern char* _acmdln; /* pointer to ascii command line */ #undef _environ extern char** _environ; /* pointer to environment block */ +extern char** __initenv; /* pointer to initial environment block */ /* LIBRARY GLOBAL VARIABLES ***************************************************/ @@ -125,7 +126,11 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) /* destroy heap */ if (nAttachCount == 0) { - + if (__initenv && __initenv != _environ) + { + free(__initenv); + __initenv = NULL; + } if (_environ) { FreeEnvironmentStringsA(_environ[0]); diff --git a/reactos/lib/msvcrt/misc/environ.c b/reactos/lib/msvcrt/misc/environ.c index 76d3da70235..e013b5d2d89 100644 --- a/reactos/lib/msvcrt/misc/environ.c +++ b/reactos/lib/msvcrt/misc/environ.c @@ -1,4 +1,4 @@ -/* $Id: environ.c,v 1.1 2002/11/24 18:42:23 robd Exp $ +/* $Id: environ.c,v 1.2 2003/04/24 16:34:26 hbirr Exp $ * * dllmain.c * @@ -44,9 +44,13 @@ int BlockEnvToEnviron(void) if (_environ) { FreeEnvironmentStringsA(_environ[0]); - free(_environ); - _environ = NULL; + if (__initenv == _environ) { + __initenv[0] == NULL; + } else { + free(_environ); + } } + _environ = NULL; ptr2 = ptr = (char*)GetEnvironmentStringsA(); if (ptr == NULL) { DPRINT("GetEnvironmentStringsA() returnd NULL\n"); @@ -67,6 +71,10 @@ int BlockEnvToEnviron(void) while (*ptr++); } _environ[i] = NULL; + if (__initenv == NULL) + { + __initenv = _environ; + } return 0; }