From b2bf21f0da168d1a88f3b52b03825699074dc91c Mon Sep 17 00:00:00 2001 From: Robert Špalek Date: Fri, 16 Oct 2009 00:09:20 +0000 Subject: Fix memory leaks when reading thumbnails svn-id: r45142 --- engines/draci/detection.cpp | 8 ++++---- engines/draci/saveload.cpp | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/engines/draci/detection.cpp b/engines/draci/detection.cpp index f9fb7ffa54..3a7301f41d 100644 --- a/engines/draci/detection.cpp +++ b/engines/draci/detection.cpp @@ -146,10 +146,10 @@ SaveStateList DraciMetaEngine::listSaves(const char *target) const { if (Draci::readSavegameHeader(in, header)) { saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); if (header.thumbnail) { - header.thumbnail->free(); - delete header.thumbnail; - } - } + header.thumbnail->free(); + delete header.thumbnail; + } + } delete in; } } diff --git a/engines/draci/saveload.cpp b/engines/draci/saveload.cpp index cebe04bf73..d4142ea433 100644 --- a/engines/draci/saveload.cpp +++ b/engines/draci/saveload.cpp @@ -62,6 +62,7 @@ bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header) { // Get the thumbnail header.thumbnail = new Graphics::Surface(); if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { + header.thumbnail->free(); delete header.thumbnail; header.thumbnail = NULL; return false; @@ -131,8 +132,13 @@ Common::Error loadSavegameData(int saveGameIdx, DraciEngine *vm) { // Skip over the savegame header DraciSavegameHeader header; - readSavegameHeader(f, header); - if (header.thumbnail) delete header.thumbnail; + if (!readSavegameHeader(f, header)) { + return Common::kNoGameDataFoundError; + } + if (header.thumbnail) { + header.thumbnail->free(); + delete header.thumbnail; + } // Pre-processing vm->_game->rememberRoomNumAsPrevious(); -- cgit v1.2.3