From 7595d6702b3fd0474a3db1a1363eccb823c2f634 Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 2 May 2026 12:51:46 +0100 Subject: [PATCH 1/4] Remove manual alloc in TryClassifyAsTD4_TD6 --- src/openrct2/FileClassifier.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/openrct2/FileClassifier.cpp b/src/openrct2/FileClassifier.cpp index a2c5ca8c47..dbc6893742 100644 --- a/src/openrct2/FileClassifier.cpp +++ b/src/openrct2/FileClassifier.cpp @@ -12,7 +12,6 @@ #include "Diagnostic.h" #include "core/Console.hpp" #include "core/FileStream.h" -#include "core/Memory.hpp" #include "core/Path.hpp" #include "core/String.hpp" #include "park/ParkFile.h" @@ -176,8 +175,7 @@ static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result) if (ValidateTrackChecksum(data.get(), dataLength)) { - std::unique_ptr)> td6data( - Memory::Allocate(0x10000), &Memory::Free); + const auto td6data = std::make_unique_for_overwrite(0x10000); size_t td6len = DecodeTD6(data.get(), td6data.get(), dataLength); if (td6data != nullptr && td6len >= 8) { From f4336f1febc1d51472edce94d962bb4bc814c500 Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 2 May 2026 12:51:47 +0100 Subject: [PATCH 2/4] Remove manual malloc and free in Win32 Platform::GetSteamPaths --- src/openrct2/platform/Platform.Win32.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 = {}; From 3fabecabc1feffdf80a082452f5847dbeab964f2 Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 2 May 2026 12:51:47 +0100 Subject: [PATCH 3/4] Remove manual new/delete in Win32 Platform::GetEnvironmentVariable --- src/openrct2/platform/Platform.Win32.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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); } From d4549d1287cc823f6b759e44b63ef49c37f08abe Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 3 May 2026 01:01:02 +0100 Subject: [PATCH 4/4] Add w prefix to names of wide string variables in Platform.Win32.cpp --- src/openrct2/platform/Platform.Win32.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index d32560bbc3..715a665d3a 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -70,9 +70,9 @@ namespace OpenRCT2::Platform } else { - const auto buffer = std::make_unique_for_overwrite(valueSize); - GetEnvironmentVariableW(wname.c_str(), buffer.get(), valueSize); - result = buffer.get(); + const auto wBuffer = std::make_unique_for_overwrite(valueSize); + GetEnvironmentVariableW(wname.c_str(), wBuffer.get(), valueSize); + result = wBuffer.get(); } return String::toUtf8(result); } @@ -754,12 +754,12 @@ namespace OpenRCT2::Platform } std::string outPath = ""; - const auto steamPath = std::make_unique_for_overwrite(size); + const auto wSteamPath = std::make_unique_for_overwrite(size); const auto result = RegQueryValueExW( - hKey, L"SteamPath", nullptr, &type, reinterpret_cast(steamPath.get()), &size); + hKey, L"SteamPath", nullptr, &type, reinterpret_cast(wSteamPath.get()), &size); if (result == ERROR_SUCCESS) { - outPath = String::toUtf8(steamPath.get()); + outPath = String::toUtf8(wSteamPath.get()); } RegCloseKey(hKey);