Merge pull request #26487 from mixiate/remove-more-manual-allocs

Remove manual memory allocs in FileClassifier and Win32 platform
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2026-05-05 21:48:50 +02:00
commit 4d02f3dca9
2 files changed
+8 -13

No files matched your search

+1 -3
View File
@@ -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<uint8_t, decltype(&Memory::Free<uint8_t>)> td6data(
Memory::Allocate<uint8_t>(0x10000), &Memory::Free<uint8_t>);
const auto td6data = std::make_unique_for_overwrite<uint8_t[]>(0x10000);
size_t td6len = DecodeTD6(data.get(), td6data.get(), dataLength);
if (td6data != nullptr && td6len >= 8)
{
+7 -10
View File
@@ -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 wBuffer = std::make_unique_for_overwrite<wchar_t[]>(valueSize);
GetEnvironmentVariableW(wname.c_str(), wBuffer.get(), valueSize);
result = wBuffer.get();
}
return String::toUtf8(result);
}
@@ -741,10 +740,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 +754,13 @@ namespace OpenRCT2::Platform
}
std::string outPath = "";
wSteamPath = reinterpret_cast<wchar_t*>(malloc(size));
result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, reinterpret_cast<LPBYTE>(wSteamPath), &size);
const auto wSteamPath = std::make_unique_for_overwrite<wchar_t[]>(size);
const auto result = RegQueryValueExW(
hKey, L"SteamPath", nullptr, &type, reinterpret_cast<LPBYTE>(wSteamPath.get()), &size);
if (result == ERROR_SUCCESS)
{
outPath = String::toUtf8(wSteamPath);
outPath = String::toUtf8(wSteamPath.get());
}
free(wSteamPath);
RegCloseKey(hKey);
SteamPaths ret = {};