diff --git a/desktop_version/src/BinaryBlob.cpp b/desktop_version/src/BinaryBlob.cpp index 0850e4bd..01abcead 100644 --- a/desktop_version/src/BinaryBlob.cpp +++ b/desktop_version/src/BinaryBlob.cpp @@ -28,6 +28,10 @@ void binaryBlob::AddFileToBinaryBlob(const char* _path) fseek(file, 0, SEEK_SET); memblock = (char*) SDL_malloc(size); + if (memblock == NULL) + { + VVV_exit(1); + } fread(memblock, 1, size, file); fclose(file); diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 074460ed..cc8a774c 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -4,11 +4,11 @@ #include #include #include -#include #include #include #include +#include "Exit.h" #include "Graphics.h" #include "UtilityClass.h" @@ -259,6 +259,10 @@ void FILESYSTEM_loadFileToMemory( ++length; *mem = static_cast(SDL_malloc(length)); // STDIN_BUFFER.data() causes double-free + if (*mem == NULL) + { + VVV_exit(1); + } std::copy(STDIN_BUFFER.begin(), STDIN_BUFFER.end(), reinterpret_cast(*mem)); return; } @@ -276,11 +280,19 @@ void FILESYSTEM_loadFileToMemory( if (addnull) { *mem = (unsigned char *) SDL_malloc(length + 1); + if (*mem == NULL) + { + VVV_exit(1); + } (*mem)[length] = 0; } else { *mem = (unsigned char*) SDL_malloc(length); + if (*mem == NULL) + { + VVV_exit(1); + } } int success = PHYSFS_readBytes(handle, *mem, length); if (success == -1) @@ -495,6 +507,10 @@ static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation) length = ftell(file); fseek(file, 0, SEEK_SET); data = (char*) SDL_malloc(length); + if (data == NULL) + { + VVV_exit(1); + } bytes_read = fread(data, 1, length, file); fclose(file); if (bytes_read != length)