diff --git a/lib/platform.c b/lib/platform.c index 75f4c69e9f..00f12fc3e6 100755 --- a/lib/platform.c +++ b/lib/platform.c @@ -268,12 +268,12 @@ int STDCALL sf_setenv(const char *name, const char *value) { char * STDCALL sf_getenv(const char *name) { #ifdef _WIN32 - static char buf[BUFSIZ]; - size_t len = 0; // We don't use it, but Windows version doesn't like to pass NULL as lenght pointer. It crashes. - return getenv_s(&len, buf, sizeof(buf) - 1, name) ? NULL : buf; -#else - return getenv(name); -#endif + char* result = NULL; + return _dupenv_s(&result, NULL, name) ? NULL : result; +# else + char* result = getenv(name); + return result ? strdup(result) : NULL; +# endif } int STDCALL sf_unsetenv(const char *name) {