1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 12:33:17 +01:00

Fix allocator mismatch in SawyerChunk on Windows with Debug

This change allows to use HeapReAlloc in FinaliseLargeTempBuffer
when running Debug builds.
This commit is contained in:
Silent
2021-05-22 15:23:52 +02:00
parent 38c7a70025
commit fb602ec0c9
3 changed files with 16 additions and 7 deletions

View File

@@ -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);
}

View File

@@ -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<uint8_t*>(std::realloc(buffer, len));
#endif

View File

@@ -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);