HDB: Fix memory leaks when stream is returned NULL

This commit is contained in:
Nipun Garg 2019-07-18 18:40:05 +05:30 committed by Eugene Sandulenko
parent ea77240d4e
commit 8d9004e432
4 changed files with 16 additions and 4 deletions

View File

@ -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();

View File

@ -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;
}

View File

@ -90,6 +90,7 @@ bool LuaScript::loadLua(const char *name) {
_systemInit = false;
delete luaStream;
return false;
}

View File

@ -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;
}