diff options
author | Sven Hesse | 2007-08-07 20:43:41 +0000 |
---|---|---|
committer | Sven Hesse | 2007-08-07 20:43:41 +0000 |
commit | d66750777503d8b05676705e46ab9640240c4b25 (patch) | |
tree | 8fc392887ee8854c6a03ce5ceb92e93bb8733050 /engines/gob | |
parent | f93ffdbc2d941129da196ed23efce4eaa92a0b01 (diff) | |
download | scummvm-rg350-d66750777503d8b05676705e46ab9640240c4b25.tar.gz scummvm-rg350-d66750777503d8b05676705e46ab9640240c4b25.tar.bz2 scummvm-rg350-d66750777503d8b05676705e46ab9640240c4b25.zip |
Fixing my leak fix...
svn-id: r28487
Diffstat (limited to 'engines/gob')
-rw-r--r-- | engines/gob/saveload.cpp | 8 | ||||
-rw-r--r-- | engines/gob/saveload.h | 5 | ||||
-rw-r--r-- | engines/gob/saveload_v2.cpp | 21 | ||||
-rw-r--r-- | engines/gob/saveload_v3.cpp | 37 |
4 files changed, 44 insertions, 27 deletions
diff --git a/engines/gob/saveload.cpp b/engines/gob/saveload.cpp index f4cb7bcf7a..ea22ede7b6 100644 --- a/engines/gob/saveload.cpp +++ b/engines/gob/saveload.cpp @@ -62,9 +62,11 @@ SaveLoad::SaveLoad(GobEngine *vm, const char *targetName) : _vm(vm) { } SaveLoad::~SaveLoad() { - for (int i = 0; i < _stagesCount; i++) - delete[] _buffer[i]; - delete[] _buffer; + if (_buffer) { + for (int i = 0; i < _stagesCount; i++) + delete[] _buffer[i]; + delete[] _buffer; + } delete _tempSprite; diff --git a/engines/gob/saveload.h b/engines/gob/saveload.h index 67a7b6335e..84a6a643e9 100644 --- a/engines/gob/saveload.h +++ b/engines/gob/saveload.h @@ -116,7 +116,7 @@ public: virtual SaveType getSaveType(const char *fileName); SaveLoad_v2(GobEngine *vm, const char *targetName); - virtual ~SaveLoad_v2(); + virtual ~SaveLoad_v2() {} protected: virtual uint32 getSaveGameSize(); @@ -130,6 +130,8 @@ protected: virtual bool saveGame(int16 dataVar, int32 size, int32 offset); virtual bool saveNotes(int16 dataVar, int32 size, int32 offset); virtual bool saveScreenshot(int16 dataVar, int32 size, int32 offset); + + void initBuffer(); }; class SaveLoad_v3 : public SaveLoad_v2 { @@ -160,6 +162,7 @@ protected: virtual bool saveScreenshot(int16 dataVar, int32 size, int32 offset); bool saveGame(int32 screenshotSize); + void initBuffer(); }; } // End of namespace Gob diff --git a/engines/gob/saveload_v2.cpp b/engines/gob/saveload_v2.cpp index 1e7506c770..b8d8d44557 100644 --- a/engines/gob/saveload_v2.cpp +++ b/engines/gob/saveload_v2.cpp @@ -38,16 +38,6 @@ SaveLoad_v2::SaveLoad_v2(GobEngine *vm, const char *targetName) : SaveLoad(vm, targetName) { _stagesCount = 1; - - _buffer = new byte*[_stagesCount]; - - assert(_buffer); - - _buffer[0] = 0; -} - -SaveLoad_v2::~SaveLoad_v2() { - delete[] _buffer; } SaveType SaveLoad_v2::getSaveType(const char *fileName) { @@ -194,6 +184,8 @@ bool SaveLoad_v2::loadScreenshot(int16 dataVar, int32 size, int32 offset) { bool SaveLoad_v2::saveGame(int16 dataVar, int32 size, int32 offset) { int32 varSize = READ_LE_UINT32(_vm->_game->_totFileData + 0x2C) * 4; + initBuffer(); + if (size == 0) { dataVar = 0; size = varSize; @@ -293,4 +285,13 @@ bool SaveLoad_v2::saveScreenshot(int16 dataVar, int32 size, int32 offset) { return false; } +void SaveLoad_v2::initBuffer() { + if (_buffer) + return; + + _buffer = new byte*[_stagesCount]; + assert(_buffer); + _buffer[0] = 0; +} + } // End of namespace Gob diff --git a/engines/gob/saveload_v3.cpp b/engines/gob/saveload_v3.cpp index d0f791d8df..f8f69342fe 100644 --- a/engines/gob/saveload_v3.cpp +++ b/engines/gob/saveload_v3.cpp @@ -45,19 +45,6 @@ SaveLoad_v3::SaveLoad_v3(GobEngine *vm, const char *targetName, _saveSlot = -1; _stagesCount = 3; - _buffer = new byte*[_stagesCount]; - - assert(_buffer); - - _buffer[0] = new byte[1000]; - _buffer[1] = new byte[1200]; - _buffer[2] = 0; - - assert(_buffer[0] && _buffer[1]); - - memset(_buffer[0], 0, 1000); - memset(_buffer[1], 0, 1200); - _useScreenshots = false; _firstSizeGame = true; } @@ -146,6 +133,8 @@ bool SaveLoad_v3::loadGame(int16 dataVar, int32 size, int32 offset) { int slot = (offset - 1700) / varSize; int slotR = (offset - 1700) % varSize; + initBuffer(); + if ((size > 0) && (offset < 500) && ((size + offset) <= 500)) { memcpy(_vm->_global->_inter_variables + dataVar, @@ -279,6 +268,8 @@ bool SaveLoad_v3::saveGame(int16 dataVar, int32 size, int32 offset) { int slot = (offset - 1700) / varSize; int slotR = (offset - 1700) % varSize; + initBuffer(); + if ((size > 0) && (offset < 500) && ((size + offset) <= 500)) { memcpy(_buffer[0] + offset, @@ -360,6 +351,8 @@ bool SaveLoad_v3::saveGame(int32 screenshotSize) { _saveSlot = -1; + initBuffer(); + if ((slot < 0) || (slot > 29)) { warning("Can't save to slot %d: Out of range", slot); delete[] _buffer[2]; @@ -433,4 +426,22 @@ bool SaveLoad_v3::saveGame(int32 screenshotSize) { return true; } +void SaveLoad_v3::initBuffer() { + if (_buffer) + return; + + _buffer = new byte*[_stagesCount]; + + assert(_buffer); + + _buffer[0] = new byte[1000]; + _buffer[1] = new byte[1200]; + _buffer[2] = 0; + + assert(_buffer[0] && _buffer[1]); + + memset(_buffer[0], 0, 1000); + memset(_buffer[1], 0, 1200); +} + } // End of namespace Gob |