diff options
-rw-r--r-- | ext/standard/basic_functions.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index b70d1971a0..fc47383784 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4088,15 +4088,17 @@ PHP_FUNCTION(getenv) size = GetEnvironmentVariableW(keyw, &dummybuf, 0); if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) { /* The environment variable doesn't exist. */ + free(keyw); RETURN_FALSE; } if (size == 0) { /* env exists, but it is empty */ + free(keyw); RETURN_EMPTY_STRING(); } - valw = emalloc(size); + valw = emalloc((size + 1) * sizeof(wchar_t)); size = GetEnvironmentVariableW(keyw, valw, size); if (size == 0) { /* has been removed between the two calls */ |