diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index aecefa3d947..58e36c3cffd 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4022,7 +4022,13 @@ PHP_FUNCTION(getenv) ptr = emalloc(size); size = GetEnvironmentVariableA(str, ptr, size); - RETURN_STRING(ptr, 0); + if (size == 0) { + /* has been removed between the two calls */ + efree(ptr); + RETURN_EMPTY_STRING(); + } else { + RETURN_STRING(ptr, 0); + } } #else /* system method returns a const */