diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index a7185bb4a6..d32560bbc3 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -70,10 +70,9 @@ namespace OpenRCT2::Platform } else { - auto wlvalue = new wchar_t[valueSize]; - GetEnvironmentVariableW(wname.c_str(), wlvalue, valueSize); - result = wlvalue; - delete[] wlvalue; + const auto buffer = std::make_unique_for_overwrite(valueSize); + GetEnvironmentVariableW(wname.c_str(), buffer.get(), valueSize); + result = buffer.get(); } return String::toUtf8(result); }