diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 558d85aa46..a7185bb4a6 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -741,10 +741,8 @@ namespace OpenRCT2::Platform SteamPaths GetSteamPaths() { - wchar_t* wSteamPath; HKEY hKey; DWORD type, size; - LRESULT result; if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", &hKey) != ERROR_SUCCESS) return {}; @@ -757,13 +755,13 @@ namespace OpenRCT2::Platform } std::string outPath = ""; - wSteamPath = reinterpret_cast(malloc(size)); - result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, reinterpret_cast(wSteamPath), &size); + const auto steamPath = std::make_unique_for_overwrite(size); + const auto result = RegQueryValueExW( + hKey, L"SteamPath", nullptr, &type, reinterpret_cast(steamPath.get()), &size); if (result == ERROR_SUCCESS) { - outPath = String::toUtf8(wSteamPath); + outPath = String::toUtf8(steamPath.get()); } - free(wSteamPath); RegCloseKey(hKey); SteamPaths ret = {};