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

tdhs at users.sourceforge.net tdhs at users.sourceforge.net
Sun Nov 7 22:08:47 CET 2010


Revision: 54127
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54127&view=rev
Author:   tdhs
Date:     2010-11-07 21:08:46 +0000 (Sun, 07 Nov 2010)

Log Message:
-----------
TOON: Corrections to close some memory leaks.

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

Modified Paths:
--------------
    scummvm/trunk/engines/toon/anim.cpp
    scummvm/trunk/engines/toon/font.cpp
    scummvm/trunk/engines/toon/font.h
    scummvm/trunk/engines/toon/hotspot.cpp
    scummvm/trunk/engines/toon/hotspot.h
    scummvm/trunk/engines/toon/path.cpp
    scummvm/trunk/engines/toon/picture.cpp
    scummvm/trunk/engines/toon/picture.h
    scummvm/trunk/engines/toon/resource.cpp
    scummvm/trunk/engines/toon/toon.cpp

Modified: scummvm/trunk/engines/toon/anim.cpp
===================================================================
--- scummvm/trunk/engines/toon/anim.cpp	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/anim.cpp	2010-11-07 21:08:46 UTC (rev 54127)
@@ -58,6 +58,7 @@
 	uint8 *currentData = fileData + 68;
 	if (_paletteEntries) {
 		if (paletteSize) {
+			delete[] _palette;
 			_palette = new uint8[paletteSize];
 			memcpy(_palette, currentData, paletteSize);
 			currentData += paletteSize;
@@ -74,6 +75,7 @@
 
 	if (READ_LE_UINT32(finalBuffer) == 0x12345678) {
 		uint8 *data = finalBuffer;
+		delete[] _frames;
 		_frames = new AnimationFrame[_numFrames];
 		for (int32 e = 0; e < _numFrames; e++) {
 			if (READ_LE_UINT32(data) != 0x12345678)
@@ -111,8 +113,9 @@
 }
 
 Animation::Animation(ToonEngine *vm) : _vm(vm) {
-	_palette = 0;
-	_frames = 0;
+	_palette = NULL;
+	_numFrames = 0;
+	_frames = NULL;
 }
 
 Animation::~Animation() {

Modified: scummvm/trunk/engines/toon/font.cpp
===================================================================
--- scummvm/trunk/engines/toon/font.cpp	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/font.cpp	2010-11-07 21:08:46 UTC (rev 54127)
@@ -32,7 +32,9 @@
 	_currentFontColor[1] = 0xc8;
 	_currentFontColor[2] = 0xcb;
 	_currentFontColor[3] = 0xce;
+}
 
+FontRenderer::~FontRenderer() {
 }
 
 // mapping extended characters required for foreign versions to font (animation)

Modified: scummvm/trunk/engines/toon/font.h
===================================================================
--- scummvm/trunk/engines/toon/font.h	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/font.h	2010-11-07 21:08:46 UTC (rev 54127)
@@ -33,7 +33,7 @@
 class FontRenderer {
 public:
 	FontRenderer(ToonEngine *vm);
-	~FontRenderer(void);
+	~FontRenderer();
 
 	void setFont(Animation *font);
 	void computeSize(Common::String origText, int32 *retX, int32 *retY);

Modified: scummvm/trunk/engines/toon/hotspot.cpp
===================================================================
--- scummvm/trunk/engines/toon/hotspot.cpp	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/hotspot.cpp	2010-11-07 21:08:46 UTC (rev 54127)
@@ -33,6 +33,8 @@
 	_numItems = 0;
 }
 
+Hotspots::~Hotspots() {
+}
 
 void Hotspots::load(Common::ReadStream *Stream) {
 	delete[] _items;

Modified: scummvm/trunk/engines/toon/hotspot.h
===================================================================
--- scummvm/trunk/engines/toon/hotspot.h	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/hotspot.h	2010-11-07 21:08:46 UTC (rev 54127)
@@ -51,7 +51,7 @@
 class Hotspots {
 public:
 	Hotspots(ToonEngine *vm);
-	~Hotspots(void);
+	~Hotspots();
 
 	bool LoadRif(Common::String rifName, Common::String additionalRifName);
 	int32 Find(int32 x, int32 y);

Modified: scummvm/trunk/engines/toon/path.cpp
===================================================================
--- scummvm/trunk/engines/toon/path.cpp	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/path.cpp	2010-11-07 21:08:46 UTC (rev 54127)
@@ -126,7 +126,7 @@
 	_width = 0;
 	_height = 0;
 	_heap = new PathFindingHeap();
-	_gridTemp = 0;
+	_gridTemp = NULL;
 	_numBlockingRects = 0;
 }
 
@@ -135,6 +135,7 @@
 		_heap->unload();
 		delete _heap;
 	}
+	delete[] _gridTemp;
 }
 
 bool PathFinding::isWalkable(int32 x, int32 y) {
@@ -323,8 +324,7 @@
 	_currentMask = mask;
 	_heap->unload();
 	_heap->init(_width * _height);
-	if (_gridTemp)
-		delete[] _gridTemp;
+	delete[] _gridTemp;
 	_gridTemp = new int32[_width*_height];
 }
 

Modified: scummvm/trunk/engines/toon/picture.cpp
===================================================================
--- scummvm/trunk/engines/toon/picture.cpp	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/picture.cpp	2010-11-07 21:08:46 UTC (rev 54127)
@@ -130,7 +130,13 @@
 }
 
 Picture::Picture(ToonEngine *vm) : _vm(vm) {
+	_data = NULL;
+	_palette = NULL;
+}
 
+Picture::~Picture() {
+	delete[] _data;
+	delete[] _palette;
 }
 
 void Picture::setupPalette() {

Modified: scummvm/trunk/engines/toon/picture.h
===================================================================
--- scummvm/trunk/engines/toon/picture.h	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/picture.h	2010-11-07 21:08:46 UTC (rev 54127)
@@ -40,6 +40,7 @@
 
 public:
 	Picture(ToonEngine *vm);
+	~Picture();
 	bool loadPicture(Common::String file, bool totalPalette = false);
 	void setupPalette();
 	void draw(Graphics::Surface &surface, int32 x, int32 y, int32 dx, int32 dy);

Modified: scummvm/trunk/engines/toon/resource.cpp
===================================================================
--- scummvm/trunk/engines/toon/resource.cpp	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/resource.cpp	2010-11-07 21:08:46 UTC (rev 54127)
@@ -184,6 +184,7 @@
 
 	if (preloadEntirePackage) {
 		_bufferSize = rs->size();
+		delete[] _buffer;
 		_buffer = new uint8[_bufferSize];
 		rs->seek(0);
 		rs->read(_buffer, _bufferSize);
@@ -191,9 +192,7 @@
 }
 
 void PakFile::close() {
-	if (_buffer) {
-		delete[] _buffer;
-	}
+	delete[] _buffer;
 
 	if (_fileHandle) {
 		_fileHandle->close();
@@ -205,11 +204,11 @@
 	close();
 }
 
-
 PakFile::PakFile() {
-	_fileHandle = 0;
-	_buffer = 0;
 	_bufferSize = 0;
+	_buffer = NULL;
+
+	_fileHandle = NULL;
 }
 
 } // End of namespace Toon

Modified: scummvm/trunk/engines/toon/toon.cpp
===================================================================
--- scummvm/trunk/engines/toon/toon.cpp	2010-11-07 19:13:30 UTC (rev 54126)
+++ scummvm/trunk/engines/toon/toon.cpp	2010-11-07 21:08:46 UTC (rev 54127)
@@ -755,6 +755,10 @@
 	DebugMan.addDebugChannel(kDebugTools, "Tools", "Tools debug level");
 	DebugMan.addDebugChannel(kDebugText, "Text", "Text debug level");
 
+	_hotspots = NULL;
+	_fontRenderer = NULL;
+	_fontToon = NULL;
+	_fontEZ = NULL;
 	_console = new ToonConsole(this);
 
 	switch (_language) {
@@ -783,6 +787,11 @@
 }
 
 ToonEngine::~ToonEngine() {
+	delete _fontRenderer;
+	delete _fontToon;
+	delete _fontEZ;
+	delete[] _hotspots;
+
 	DebugMan.clearAllDebugChannels();
 	delete _console;
 }


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