diff options
author | Nipun Garg | 2019-07-18 18:40:05 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:17:23 +0200 |
commit | 8d9004e43268109394059ff267cce9983c4f5346 (patch) | |
tree | 4a8cdd459be080f966283cad4205b05e3a60402d | |
parent | ea77240d4e85873fd5f006b10981509156ddba73 (diff) | |
download | scummvm-rg350-8d9004e43268109394059ff267cce9983c4f5346.tar.gz scummvm-rg350-8d9004e43268109394059ff267cce9983c4f5346.tar.bz2 scummvm-rg350-8d9004e43268109394059ff267cce9983c4f5346.zip |
HDB: Fix memory leaks when stream is returned NULL
-rw-r--r-- | engines/hdb/gfx.cpp | 16 | ||||
-rw-r--r-- | engines/hdb/hdb.cpp | 2 | ||||
-rw-r--r-- | engines/hdb/lua-script.cpp | 1 | ||||
-rw-r--r-- | engines/hdb/map.cpp | 1 |
4 files changed, 16 insertions, 4 deletions
diff --git a/engines/hdb/gfx.cpp b/engines/hdb/gfx.cpp index bc6046dae1..8c7cb052b4 100644 --- a/engines/hdb/gfx.cpp +++ b/engines/hdb/gfx.cpp @@ -383,8 +383,10 @@ void Gfx::turnOnSnow() { Picture *Gfx::loadPic(const char *picName) { Picture *pic = new Picture; Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(picName, TYPE_PIC); - if (!stream) + if (!stream) { + delete stream; return NULL; + } pic->load(stream); delete stream; return pic; @@ -393,8 +395,10 @@ Picture *Gfx::loadPic(const char *picName) { Tile *Gfx::loadTile(const char *tileName) { Tile *tile = new Tile; Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(tileName, TYPE_TILE32); - if (!stream) + if (!stream) { + delete stream; return NULL; + } tile->load(stream); delete stream; return tile; @@ -403,8 +407,10 @@ Tile *Gfx::loadTile(const char *tileName) { Tile *Gfx::loadIcon(const char *tileName) { Tile *tile = new Tile; Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(tileName, TYPE_ICON32); - if (!stream) + if (!stream) { + delete stream; return NULL; + } tile->load(stream); delete stream; return tile; @@ -709,8 +715,10 @@ int Gfx::animateTile(int tileIndex) { bool Gfx::loadFont(const char *string) { Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(string, TYPE_FONT); - if (!stream) + if (!stream) { + delete stream; return false; + } // Loading _fontHeader _fontHeader.type = (int)stream->readUint32LE(); diff --git a/engines/hdb/hdb.cpp b/engines/hdb/hdb.cpp index 25b860495d..3419ac6cee 100644 --- a/engines/hdb/hdb.cpp +++ b/engines/hdb/hdb.cpp @@ -830,6 +830,7 @@ Common::Error HDBGame::run() { Common::SeekableReadStream *titleStream = _fileMan->findFirstData("monkeylogoscreen", TYPE_PIC); if (titleStream == NULL) { debug("The TitleScreen MPC entry can't be found."); + delete titleStream; return Common::kReadingFailed; } @@ -840,6 +841,7 @@ Common::Error HDBGame::run() { Common::SeekableReadStream *tileStream = _fileMan->findFirstData("t32_ground1", TYPE_TILE32); if (tileStream == NULL) { debug("The t32_shipwindow_lr MPC entry can't be found."); + delete tileStream; return Common::kReadingFailed; } diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp index 54cd2c9846..5c2906b6dc 100644 --- a/engines/hdb/lua-script.cpp +++ b/engines/hdb/lua-script.cpp @@ -90,6 +90,7 @@ bool LuaScript::loadLua(const char *name) { _systemInit = false; + delete luaStream; return false; } diff --git a/engines/hdb/map.cpp b/engines/hdb/map.cpp index 450f182927..e1d21c4f0c 100644 --- a/engines/hdb/map.cpp +++ b/engines/hdb/map.cpp @@ -260,6 +260,7 @@ bool Map::loadMap(char *name) { Common::SeekableReadStream *mapStream = g_hdb->_fileMan->findFirstData(name, TYPE_BINARY); if (mapStream == NULL) { warning("The %s MPC entry can't be found", name); + delete mapStream; return false; } |