FULLPIPE: Fix memory leak of save game thumbnail

This commit is contained in:
Colin Snover 2017-11-14 12:52:22 -06:00 committed by Eugene Sandulenko
parent ff96db23df
commit 5c89c39325
4 changed files with 9 additions and 12 deletions

View File

@ -180,13 +180,11 @@ SaveStateList FullpipeMetaEngine::listSaves(const char *target) const {
int slotNum = atoi(file->c_str() + file->size() - 2);
if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) {
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
Common::ScopedPtr<Common::InSaveFile> in(saveFileMan->openForLoading(*file));
if (in) {
Fullpipe::FullpipeSavegameHeader header;
Fullpipe::readSavegameHeader(in, header);
Fullpipe::readSavegameHeader(in.get(), header);
saveList.push_back(SaveStateDescriptor(slotNum, header.saveName));
delete header.thumbnail;
delete in;
}
}
}
@ -201,13 +199,12 @@ void FullpipeMetaEngine::removeSaveState(const char *target, int slot) const {
}
SaveStateDescriptor FullpipeMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(
Fullpipe::getSavegameFile(slot));
Common::ScopedPtr<Common::InSaveFile> f(g_system->getSavefileManager()->openForLoading(
Fullpipe::getSavegameFile(slot)));
if (f) {
Fullpipe::FullpipeSavegameHeader header;
Fullpipe::readSavegameHeader(f, header);
delete f;
Fullpipe::readSavegameHeader(f.get(), header);
// Create the return descriptor
SaveStateDescriptor desc(slot, header.saveName);

View File

@ -23,6 +23,7 @@
#ifndef FULLPIPE_GAMELOADER_H
#define FULLPIPE_GAMELOADER_H
#include "common/ptr.h"
#include "engines/savestate.h"
#include "fullpipe/objects.h"
@ -83,7 +84,7 @@ struct FullpipeSavegameHeader {
uint32 date;
uint16 time;
uint32 playtime;
Graphics::Surface *thumbnail;
Common::SharedPtr<Graphics::Surface> thumbnail;
};
struct SaveHeader {

View File

@ -195,8 +195,6 @@ void fillDummyHeader(Fullpipe::FullpipeSavegameHeader &header) {
}
bool readSavegameHeader(Common::InSaveFile *in, FullpipeSavegameHeader &header) {
header.thumbnail = NULL;
uint oldPos = in->pos();
in->seek(-4, SEEK_END);
@ -239,7 +237,7 @@ bool readSavegameHeader(Common::InSaveFile *in, FullpipeSavegameHeader &header)
header.saveName = Common::String::format("%s %s", desc.getSaveDate().c_str(), desc.getSaveTime().c_str());
// Get the thumbnail
header.thumbnail = Graphics::loadThumbnail(*in);
header.thumbnail = Common::SharedPtr<Graphics::Surface>(Graphics::loadThumbnail(*in), Graphics::SurfaceDeleter());
in->seek(oldPos, SEEK_SET); // Rewind the file

View File

@ -121,6 +121,7 @@ public:
* Hence the caller must not delete the surface.
*/
void setThumbnail(Graphics::Surface *t);
void setThumbnail(Common::SharedPtr<Graphics::Surface> t) { _thumbnail = t; }
/**
* Sets the date the save state was created.