From bd97378862c6b01d1de59f59a98a8a53a74fb696 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 13 Feb 2021 17:20:48 -0800 Subject: [PATCH] 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. --- desktop_version/src/BinaryBlob.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/desktop_version/src/BinaryBlob.cpp b/desktop_version/src/BinaryBlob.cpp index 36bb9697..a4a4779b 100644 --- a/desktop_version/src/BinaryBlob.cpp +++ b/desktop_version/src/BinaryBlob.cpp @@ -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)