diff --git a/src/openrct2/rct12/SawyerChunk.cpp b/src/openrct2/rct12/SawyerChunk.cpp index b5db22a579..6873c94924 100644 --- a/src/openrct2/rct12/SawyerChunk.cpp +++ b/src/openrct2/rct12/SawyerChunk.cpp @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2020 OpenRCT2 developers + * Copyright (c) 2014-2021 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -10,6 +10,7 @@ #include "SawyerChunk.h" #include "../core/Memory.hpp" +#include "SawyerChunkReader.h" SawyerChunk::SawyerChunk(SAWYER_ENCODING encoding, void* data, size_t length) { @@ -20,5 +21,5 @@ SawyerChunk::SawyerChunk(SAWYER_ENCODING encoding, void* data, size_t length) SawyerChunk::~SawyerChunk() { - Memory::Free(_data); + SawyerChunkReader::FreeChunk(_data); } diff --git a/src/openrct2/rct12/SawyerChunkReader.cpp b/src/openrct2/rct12/SawyerChunkReader.cpp index f1bf44933f..4f584130ae 100644 --- a/src/openrct2/rct12/SawyerChunkReader.cpp +++ b/src/openrct2/rct12/SawyerChunkReader.cpp @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2020 OpenRCT2 developers + * Copyright (c) 2014-2021 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -158,6 +158,11 @@ void SawyerChunkReader::ReadChunk(void* dst, size_t length) } } +void SawyerChunkReader::FreeChunk(void* data) +{ + FreeLargeTempBuffer(data); +} + size_t SawyerChunkReader::DecodeChunk(void* dst, size_t dstCapacity, const void* src, const sawyercoding_chunk_header& header) { size_t resultLength; @@ -315,9 +320,7 @@ void* SawyerChunkReader::AllocateLargeTempBuffer() void* SawyerChunkReader::FinaliseLargeTempBuffer(void* buffer, size_t len) { #ifdef __USE_HEAP_ALLOC__ - auto finalBuffer = std::malloc(len); - std::memcpy(finalBuffer, buffer, len); - HeapFree(GetProcessHeap(), 0, buffer); + auto finalBuffer = HeapReAlloc(GetProcessHeap(), 0, buffer, len); #else auto finalBuffer = static_cast(std::realloc(buffer, len)); #endif diff --git a/src/openrct2/rct12/SawyerChunkReader.h b/src/openrct2/rct12/SawyerChunkReader.h index 8fb370b25e..9d68f55726 100644 --- a/src/openrct2/rct12/SawyerChunkReader.h +++ b/src/openrct2/rct12/SawyerChunkReader.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2020 OpenRCT2 developers + * Copyright (c) 2014-2021 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -84,6 +84,11 @@ public: return result; } + /** + * Frees the chunk data, to be used when destructing SawyerChunks + */ + static void FreeChunk(void* data); + private: static size_t DecodeChunk(void* dst, size_t dstCapacity, const void* src, const sawyercoding_chunk_header& header); static size_t DecodeChunkRLERepeat(void* dst, size_t dstCapacity, const void* src, size_t srcLength);