From cdeedf3bb4a50d3421002ff239ea5612ac79363e Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Sun, 1 Jun 2003 17:08:03 +0000 Subject: [PATCH] - Do not free the environment strings from the initial environment. svn path=/trunk/; revision=4811 --- reactos/lib/msvcrt/misc/dllmain.c | 7 ++++--- reactos/lib/msvcrt/misc/environ.c | 14 +++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/reactos/lib/msvcrt/misc/dllmain.c b/reactos/lib/msvcrt/misc/dllmain.c index fb7d6804bf1..2746a00580a 100644 --- a/reactos/lib/msvcrt/misc/dllmain.c +++ b/reactos/lib/msvcrt/misc/dllmain.c @@ -1,4 +1,4 @@ -/* $Id: dllmain.c,v 1.18 2003/04/24 16:34:26 hbirr Exp $ +/* $Id: dllmain.c,v 1.19 2003/06/01 17:08:03 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.18 $ + * $Revision: 1.19 $ * $Author: hbirr $ - * $Date: 2003/04/24 16:34:26 $ + * $Date: 2003/06/01 17:08:03 $ * */ @@ -128,6 +128,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) { if (__initenv && __initenv != _environ) { + FreeEnvironmentStringsA(__initenv[0]); free(__initenv); __initenv = NULL; } diff --git a/reactos/lib/msvcrt/misc/environ.c b/reactos/lib/msvcrt/misc/environ.c index e013b5d2d89..ed4b71bd379 100644 --- a/reactos/lib/msvcrt/misc/environ.c +++ b/reactos/lib/msvcrt/misc/environ.c @@ -1,4 +1,4 @@ -/* $Id: environ.c,v 1.2 2003/04/24 16:34:26 hbirr Exp $ +/* $Id: environ.c,v 1.3 2003/06/01 17:08:03 hbirr Exp $ * * dllmain.c * @@ -42,13 +42,9 @@ int BlockEnvToEnviron(void) DPRINT("BlockEnvToEnviron()\n"); - if (_environ) { + if (_environ && _environ != __initenv) { FreeEnvironmentStringsA(_environ[0]); - if (__initenv == _environ) { - __initenv[0] == NULL; - } else { - free(_environ); - } + free(_environ); } _environ = NULL; ptr2 = ptr = (char*)GetEnvironmentStringsA(); @@ -59,7 +55,7 @@ int BlockEnvToEnviron(void) len = 0; while (*ptr2) { len++; - while (*ptr2++); + ptr2 += strlen(ptr2) + 1; } _environ = malloc((len + 1) * sizeof(char*)); if (_environ == NULL) { @@ -68,7 +64,7 @@ int BlockEnvToEnviron(void) } for (i = 0; i < len && *ptr; i++) { _environ[i] = ptr; - while (*ptr++); + ptr += strlen(ptr) + 1; } _environ[i] = NULL; if (__initenv == NULL)