all repos — mgba @ 971a322f09f731b028acec543ba1d8de29ca2b90

mGBA Game Boy Advance Emulator

GBA: Better memory handling with PNG savestates
Jeffrey Pfau jeffrey@endrift.com
Sun, 30 Aug 2015 19:14:59 -0700
commit

971a322f09f731b028acec543ba1d8de29ca2b90

parent

0d5b6b84c1588fa7462e4ece460d4a1c15915cfb

2 files changed, 11 insertions(+), 4 deletions(-)

jump to
M CHANGESCHANGES

@@ -9,6 +9,7 @@ - GBA: Deinit savegame when unloading a ROM

Misc: - Qt: Remove useless help icons in dialogs - GBA: Attempting to save a screenshot-style savestate should be allowed without libpng + - GBA: Better memory handling with PNG savestates 0.3.0: (2015-08-16) Features:
M src/gba/serialize.csrc/gba/serialize.c

@@ -234,12 +234,14 @@ static int _loadPNGChunkHandler(png_structp png, png_unknown_chunkp chunk) {

if (strcmp((const char*) chunk->name, "gbAs") != 0) { return 0; } - struct GBASerializedState state; - uLongf len = sizeof(state); - uncompress((Bytef*) &state, &len, chunk->data, chunk->size); - if (!GBADeserialize(png_get_user_chunk_ptr(png), &state)) { + struct GBASerializedState* state = malloc(sizeof(*state)); + uLongf len = sizeof(*state); + uncompress((Bytef*) state, &len, chunk->data, chunk->size); + if (!GBADeserialize(png_get_user_chunk_ptr(png), state)) { + free(state); longjmp(png_jmpbuf(png), 1); } + free(state); return 1; }

@@ -252,6 +254,10 @@ PNGReadClose(png, info, end);

return false; } uint32_t* pixels = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); + if (!pixels) { + PNGReadClose(png, info, end); + return false; + } PNGInstallChunkHandler(png, gba, _loadPNGChunkHandler, "gbAs"); bool success = PNGReadHeader(png, info);