1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 06:28:30 +02:00

Unconditionally free and zero in binaryBlob::clear()

The function previously conditionally freed a m_memblocks pointer if its
corresponding m_headers was valid. This makes me slightly worried about
the possibility that memory would be allocated, but the header would
still be marked as invalid.

I don't see how that could happen, but it's better to be safe than
sorry. SDL_free() does a guaranteed NULL pointer check (like most SDL
functions), so it's okay to pass NULL pointers to it.

Just to be sure, I'm also zeroing m_memblocks and m_headers after
freeing everything in the function.
This commit is contained in:
Misa 2021-02-13 17:20:48 -08:00 committed by Ethan Lee
parent 47df6c9d66
commit bd97378862

View File

@ -139,12 +139,10 @@ void binaryBlob::clear()
{
for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1)
{
if (m_headers[i].valid)
{
SDL_free(m_memblocks[i]);
m_headers[i].valid = false;
}
SDL_free(m_memblocks[i]);
}
SDL_zeroa(m_memblocks);
SDL_zeroa(m_headers);
}
int binaryBlob::getIndex(const char* _name)