From ea7ea9f07548dd64ba71aab3f254fe3a0063c195 Mon Sep 17 00:00:00 2001 From: Eric Fry Date: Mon, 2 Mar 2020 22:03:55 +1100 Subject: [PATCH] DRAGONS: Coverity Scan fixes. Memory leaks, uninitialised variables. --- engines/dragons/actor.cpp | 4 ++++ engines/dragons/actorresource.cpp | 13 +++++++++++++ engines/dragons/actorresource.h | 2 ++ engines/dragons/background.h | 8 ++++++++ engines/dragons/dragonini.cpp | 2 ++ engines/dragons/dragonrms.cpp | 1 + engines/dragons/dragons.cpp | 2 ++ engines/dragons/inventory.cpp | 1 + 8 files changed, 33 insertions(+) diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp index 37d0e703f85..d3081f0ae68 100644 --- a/engines/dragons/actor.cpp +++ b/engines/dragons/actor.cpp @@ -57,6 +57,7 @@ Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, in } else { //TODO run find by resource and remove from mem logic here. @0x800358c8 debug("Unable to find free actor slot!!"); + delete resource; } resetDisplayOrder(); return actor; @@ -149,6 +150,7 @@ Actor::Actor(uint16 id) : _actorID(id) { void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) { debug(3, "actor %d Init", _actorID); + delete _actorResource; _actorResource = resource; _x_pos = x; _y_pos = y; @@ -209,6 +211,8 @@ void Actor::reset_maybe() { _flags = 0; //TODO actor_find_by_resourceId_and_remove_resource_from_mem_maybe(resourceID); freeFrame(); + delete _actorResource; + _actorResource = NULL; } uint32 calcDistance(int32 x1, int32 y1, int32 x2, int32 y2) { diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp index dae8f50ea5d..05b579196a6 100644 --- a/engines/dragons/actorresource.cpp +++ b/engines/dragons/actorresource.cpp @@ -186,4 +186,17 @@ byte *ActorResource::getPalette() { return _palette; } +ActorResource::ActorResource() : _id(0), _data(nullptr), _fileSize(0), _frames(nullptr), + _framesCount(0), + _sequenceTableOffset(0) { + memset(_palette, 0, 512); +} + +ActorResource::~ActorResource() { + if (_data) { + free(_data); + } + delete _frames; +} + } // End of namespace Dragons diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h index b9d35ca384e..9162dc9d255 100644 --- a/engines/dragons/actorresource.h +++ b/engines/dragons/actorresource.h @@ -67,6 +67,8 @@ private: //uint16 _sequenceCount; public: + ActorResource(); + ~ActorResource(); bool load(uint32 id, byte *dataStart, Common::SeekableReadStream &stream); Graphics::Surface *loadFrame(ActorFrame &frameNumber, byte *palette); ActorFrame *loadFrameHeader(uint16 frameOffset); diff --git a/engines/dragons/background.h b/engines/dragons/background.h index 549ed398852..e00b339bd80 100644 --- a/engines/dragons/background.h +++ b/engines/dragons/background.h @@ -71,6 +71,14 @@ struct TileMap { uint32 size; byte *map; uint16 tileIndexOffset; + + TileMap() { + w = 0; + h = 0; + size = 0; + map = nullptr; + tileIndexOffset = 0; + } }; class Background { diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp index afa10fa3992..cca789e7413 100644 --- a/engines/dragons/dragonini.cpp +++ b/engines/dragons/dragonini.cpp @@ -64,6 +64,8 @@ void DragonINIResource::reset() { } _flickerINI = &_dragonINI[0]; + + delete readStream; } DragonINI *DragonINIResource::getRecord(uint16 index) { diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp index a62c7d0836a..27b7b7443fe 100644 --- a/engines/dragons/dragonrms.cpp +++ b/engines/dragons/dragonrms.cpp @@ -47,6 +47,7 @@ DragonRMS::DragonRMS(BigfileArchive *bigfileArchive, DragonOBD *dragonOBD) : _dr _rmsObjects[i]._field16 = readStream->readSint32LE(); _rmsObjects[i]._field1a = readStream->readSint16LE(); } + delete readStream; } char *DragonRMS::getSceneName(uint32 sceneId) { diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp index 094764e644e..4b203223acc 100644 --- a/engines/dragons/dragons.cpp +++ b/engines/dragons/dragons.cpp @@ -96,6 +96,8 @@ DragonsEngine::DragonsEngine(OSystem *syst, const ADGameDescription *desc) : Eng _debugMode = false; _isGamePaused = false; + _bit_flags_8006fbd8 = 0; + reset(); } diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp index 3af6d3d1541..2ec2f1dc5e1 100644 --- a/engines/dragons/inventory.cpp +++ b/engines/dragons/inventory.cpp @@ -68,6 +68,7 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) { _screenPositionIndex = 0; _previousState = Closed; _bag = NULL; + _actor = NULL; _inventionBookPrevSceneUpdateFunc = NULL; _inventionBookPrevSceneId = 0;