From d7f51ee28bff6a77447715fee690bb5540d257da Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sat, 29 Jun 2013 06:04:58 +0000 Subject: [PATCH] =?UTF-8?q?[CRT]=20-=20Handle=20realloc=20failure=20in=20S?= =?UTF-8?q?etEnv.=20Based=20on=20patch=20by=20Samuel=20Serapi=C3=B3n=20COR?= =?UTF-8?q?E-7306=20#resolve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/trunk/; revision=59354 --- reactos/lib/sdk/crt/misc/environ.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/reactos/lib/sdk/crt/misc/environ.c b/reactos/lib/sdk/crt/misc/environ.c index 24481939017..975ab521f43 100644 --- a/reactos/lib/sdk/crt/misc/environ.c +++ b/reactos/lib/sdk/crt/misc/environ.c @@ -214,6 +214,8 @@ int SetEnv(const wchar_t *option) wchar_t *woption; char *mboption; int remove, index, count, size, result = 0, found = 0; + wchar_t **wnewenv; + char **mbnewenv; if (option == NULL || (epos = wcschr(option, L'=')) == NULL) return -1; @@ -261,14 +263,18 @@ int SetEnv(const wchar_t *option) free(*wenvptr); for (count = index; *wenvptr != NULL; wenvptr++, count++) *wenvptr = *(wenvptr + 1); - _wenviron = realloc(_wenviron, count * sizeof(wchar_t*)); + wnewenv = realloc(_wenviron, count * sizeof(wchar_t*)); + if (wnewenv != NULL) + _wenviron = wnewenv; /* Remove the option from multibyte environment. We assume * the environments are in sync and the option is at the * same position. */ free(_environ[index]); memmove(&_environ[index], &_environ[index+1], (count - index) * sizeof(char*)); - _environ = realloc(_environ, count * sizeof(char*)); + mbnewenv = realloc(_environ, count * sizeof(char*)); + if (mbnewenv != NULL) + _environ = mbnewenv; result = SetEnvironmentVariableW(name, NULL) ? 0 : -1; } @@ -303,9 +309,6 @@ int SetEnv(const wchar_t *option) } else { - wchar_t **wnewenv; - char **mbnewenv; - /* Get the size of the original environment. */ for (count = index; *wenvptr != NULL; wenvptr++, count++) ;