Skip to content

Commit

Permalink
Unconditionally free and zero in binaryBlob::clear()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
InfoTeddy authored and flibitijibibo committed Feb 16, 2021
1 parent 47df6c9 commit bd97378
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions desktop_version/src/BinaryBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bd97378

Please sign in to comment.