[Scummvm-cvs-logs] SF.net SVN: scummvm:[54136] scummvm/trunk/engines/toon

tdhs at users.sourceforge.net tdhs at users.sourceforge.net
Mon Nov 8 04:14:33 CET 2010


Revision: 54136
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54136&view=rev
Author:   tdhs
Date:     2010-11-08 03:14:32 +0000 (Mon, 08 Nov 2010)

Log Message:
-----------
TOON: Further corrections to close memory leaks.

These corrections close a number of leaks in the Toon engine reported by running Valgrind with --leak-check=full option, but a significant number still remain.

Modified Paths:
--------------
    scummvm/trunk/engines/toon/audio.cpp
    scummvm/trunk/engines/toon/character.cpp
    scummvm/trunk/engines/toon/path.cpp
    scummvm/trunk/engines/toon/path.h
    scummvm/trunk/engines/toon/script.cpp
    scummvm/trunk/engines/toon/script.h
    scummvm/trunk/engines/toon/script_func.cpp
    scummvm/trunk/engines/toon/toon.cpp

Modified: scummvm/trunk/engines/toon/audio.cpp
===================================================================
--- scummvm/trunk/engines/toon/audio.cpp	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/audio.cpp	2010-11-08 03:14:32 UTC (rev 54136)
@@ -482,16 +482,13 @@
 }
 
 AudioStreamPackage::AudioStreamPackage(ToonEngine *vm) : _vm(vm) {
-	_indexBuffer = 0;
-	_file = 0;
+	_indexBuffer = NULL;
+	_file = NULL;
 }
 
 AudioStreamPackage::~AudioStreamPackage() {
 	delete[] _indexBuffer;
-	if (_file) {
-		delete _file;
-		_file = 0;
-	}
+	delete _file;
 }
 
 bool AudioStreamPackage::loadAudioPackage(Common::String indexFile, Common::String streamFile) {
@@ -503,7 +500,6 @@
 		return false;
 
 	delete[] _indexBuffer;
-
 	_indexBuffer = new uint32[size / 4];
 	memcpy(_indexBuffer, fileData, size);
 

Modified: scummvm/trunk/engines/toon/character.cpp
===================================================================
--- scummvm/trunk/engines/toon/character.cpp	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/character.cpp	2010-11-08 03:14:32 UTC (rev 54136)
@@ -32,8 +32,8 @@
 
 Character::Character(ToonEngine *vm) : _vm(vm) {
 	_animationInstance = 0;
-	_shadowAnimationInstance = 0;
-	_shadowAnim = 0;
+	_shadowAnimationInstance = NULL;
+	_shadowAnim = NULL;
 	_x = 0;
 	_y = 0;
 	_z = 0;
@@ -64,6 +64,8 @@
 }
 
 Character::~Character(void) {
+	delete _shadowAnimationInstance;
+	delete _shadowAnim;
 }
 
 void Character::init() {
@@ -918,10 +920,12 @@
 bool Character::loadShadowAnimation(Common::String animName) {
 	debugC(1, kDebugCharacter, "loadShadowAnimation(%s)", animName.c_str());
 
+	delete _shadowAnim;
 	_shadowAnim = new Animation(_vm);
 	if (!_shadowAnim->loadAnimation(animName))
 		return false;
 
+	delete _shadowAnimationInstance;
 	_shadowAnimationInstance = _vm->getAnimationManager()->createNewInstance(kAnimationCharacter);
 	_vm->getAnimationManager()->addInstance(_shadowAnimationInstance);
 	_shadowAnimationInstance->setAnimation(_shadowAnim);

Modified: scummvm/trunk/engines/toon/path.cpp
===================================================================
--- scummvm/trunk/engines/toon/path.cpp	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/path.cpp	2010-11-08 03:14:32 UTC (rev 54136)
@@ -27,9 +27,20 @@
 
 namespace Toon {
 
+PathFindingHeap::PathFindingHeap() {
+	_count = 0;
+	_alloc = 0;
+	_data = NULL;
+}
+
+PathFindingHeap::~PathFindingHeap() {
+	delete[] _data;
+}
+
 int32 PathFindingHeap::init(int32 size) {
 	debugC(1, kDebugPath, "init(%d)", size);
 
+	delete[] _data;
 	_data = new HeapDataGrid[size * 2];
 	memset(_data, 0, sizeof(HeapDataGrid) * size * 2);
 	_count = 0;
@@ -38,8 +49,8 @@
 }
 
 int32 PathFindingHeap::unload() {
-	if (_data)
-		delete[] _data;
+	delete[] _data;
+	_data = NULL;
 	return 0;
 }
 
@@ -131,10 +142,9 @@
 }
 
 PathFinding::~PathFinding(void) {
-	if (_heap) {
+	if (_heap)
 		_heap->unload();
-		delete _heap;
-	}
+	delete _heap;
 	delete[] _gridTemp;
 }
 

Modified: scummvm/trunk/engines/toon/path.h
===================================================================
--- scummvm/trunk/engines/toon/path.h	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/path.h	2010-11-08 03:14:32 UTC (rev 54136)
@@ -37,24 +37,27 @@
 };
 
 class PathFindingHeap {
+public:
+	PathFindingHeap();
+	~PathFindingHeap();
 
-private:
-	HeapDataGrid *_data;
-public:
 	int32 _alloc;
 	int32 _count;
+
 	int32 push(int32 x, int32 y, int32 weight);
 	int32 pop(int32 *x, int32 *y, int32 *weight);
 	int32 init(int32 size);
 	int32 clear();
 	int32 unload();
+
+private:
+	HeapDataGrid *_data;
 };
 
-
 class PathFinding {
 public:
 	PathFinding(ToonEngine *vm);
-	~PathFinding(void);
+	~PathFinding();
 
 	int32 findPath(int32 x, int32 y, int32 destX, int32 destY);
 	int32 findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX = -1, int origY = -1);

Modified: scummvm/trunk/engines/toon/script.cpp
===================================================================
--- scummvm/trunk/engines/toon/script.cpp	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/script.cpp	2010-11-08 03:14:32 UTC (rev 54136)
@@ -66,6 +66,9 @@
 #undef OPCODE
 }
 
+EMCInterpreter::~EMCInterpreter() {
+}
+
 bool EMCInterpreter::callback(Common::IFFChunk &chunk) {
 	switch (chunk._type) {
 	case MKID_BE('TEXT'):

Modified: scummvm/trunk/engines/toon/script.h
===================================================================
--- scummvm/trunk/engines/toon/script.h	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/script.h	2010-11-08 03:14:32 UTC (rev 54136)
@@ -98,6 +98,7 @@
 class EMCInterpreter {
 public:
 	EMCInterpreter(ToonEngine *vm);
+	~EMCInterpreter();
 
 	bool load(const char *filename, EMCData *data, const Common::Array<const OpcodeV2 *> *opcodes);
 	void unload(EMCData *data);
@@ -147,6 +148,7 @@
 	void op_eval(EMCState *);
 	void op_setRetAndJmp(EMCState *);
 };
+
 } // End of namespace Toon
 
 #endif

Modified: scummvm/trunk/engines/toon/script_func.cpp
===================================================================
--- scummvm/trunk/engines/toon/script_func.cpp	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/script_func.cpp	2010-11-08 03:14:32 UTC (rev 54136)
@@ -223,7 +223,10 @@
 }
 
 ScriptFunc::~ScriptFunc(void) {
-
+	while(!_opcodes.empty()) {
+		//delete _opcodes.end();
+		_opcodes.pop_back();
+	}
 }
 
 char *GetText(int32 i, EMCState *state) {

Modified: scummvm/trunk/engines/toon/toon.cpp
===================================================================
--- scummvm/trunk/engines/toon/toon.cpp	2010-11-08 00:45:47 UTC (rev 54135)
+++ scummvm/trunk/engines/toon/toon.cpp	2010-11-08 03:14:32 UTC (rev 54136)
@@ -131,7 +131,6 @@
 	memset(_sceneAnimations, 0, sizeof(_sceneAnimations));
 	memset(_sceneAnimationScripts, 0, sizeof(_sceneAnimationScripts));
 
-
 	_gameState->_currentChapter = 1;
 	initChapter();
 	loadCursor();
@@ -755,10 +754,16 @@
 	DebugMan.addDebugChannel(kDebugTools, "Tools", "Tools debug level");
 	DebugMan.addDebugChannel(kDebugText, "Text", "Text debug level");
 
-	_hotspots = NULL;
+	_moviePlayer = NULL;
+	_mainSurface = NULL;
 	_fontRenderer = NULL;
 	_fontToon = NULL;
 	_fontEZ = NULL;
+	_hotspots = NULL;
+	_genericTexts = NULL;
+	_roomTexts = NULL;
+	_script_func = NULL;
+	_script = NULL;
 	_console = new ToonConsole(this);
 
 	switch (_language) {
@@ -787,10 +792,17 @@
 }
 
 ToonEngine::~ToonEngine() {
+	delete _moviePlayer;
+	delete _mainSurface;
+
 	delete _fontRenderer;
 	delete _fontToon;
 	delete _fontEZ;
 	delete _hotspots;
+	delete _genericTexts;
+	delete _roomTexts;
+	delete _script_func;
+	delete _script;
 
 	DebugMan.clearAllDebugChannels();
 	delete _console;
@@ -1171,6 +1183,7 @@
 	memset(&data, 0, sizeof(data));
 	memset(&status, 0, sizeof(status));
 
+	delete _script;
 	_script = new EMCInterpreter(this);
 
 	_script->load("_START01.EMC", &data, &_script_func->_opcodes);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list