Index: lib/sdk/crt/misc/environ.c =================================================================== --- lib/sdk/crt/misc/environ.c (revision 59223) +++ lib/sdk/crt/misc/environ.c (working copy) @@ -213,6 +213,7 @@ wchar_t **wenvptr; wchar_t *woption; char *mboption; + char **_environ_temp; int remove, index, count, size, result = 0, found = 0; if (option == NULL || (epos = wcschr(option, L'=')) == NULL) @@ -268,8 +269,17 @@ * same position. */ free(_environ[index]); memmove(&_environ[index], &_environ[index+1], (count - index) * sizeof(char*)); - _environ = realloc(_environ, count * sizeof(char*)); + _environ_temp = realloc(_environ, count * sizeof(char*)); + if(_environ_temp != NULL) + { + _environ = _environ_temp; + } + else + { + free(_environ); + } + result = SetEnvironmentVariableW(name, NULL) ? 0 : -1; } else