update for HEAD-2003050101
[reactos.git] / lib / msvcrt / misc / environ.c
index 7dc8d43..df0fef9 100644 (file)
@@ -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;
 }