[Scummvm-cvs-logs] CVS: scummvm/simon sound.cpp,1.62,1.63

Oliver Kiehl olki at users.sourceforge.net
Mon Jan 19 09:47:01 CET 2004


Update of /cvsroot/scummvm/scummvm/simon
In directory sc8-pr-cvs1:/tmp/cvs-serv29883

Modified Files:
	sound.cpp 
Log Message:
fix memory leak


Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/sound.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- sound.cpp	19 Jan 2004 17:44:04 -0000	1.62
+++ sound.cpp	19 Jan 2004 17:46:08 -0000	1.63
@@ -32,6 +32,7 @@
 	File *_file;
 	uint32 *_offsets;
 	SoundMixer *_mixer;
+	bool _freeOffsets;
 
 public:
 	BaseSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false);
@@ -74,6 +75,7 @@
 	res = size / sizeof(uint32);
 
 	_offsets = (uint32 *)malloc(size + sizeof(uint32));
+	_freeOffsets = true;
 
 	_file->seek(base, SEEK_SET);
 
@@ -99,10 +101,12 @@
 	_mixer = mixer;
 	_file = file;
 	_offsets = offsets;
+	_freeOffsets = false;
 }
 
 BaseSound::~BaseSound() {
-	free(_offsets);
+	if (_freeOffsets)
+		free(_offsets);
 	delete _file;
 }
 
@@ -231,7 +235,7 @@
 	while (_offsets[sound + i] == _offsets[sound])
 			i++;
 
-	uint32 size = _offsets[sound + i] - _offsets[sound];
+	uint32 size = _offsets[sound+1] - _offsets[sound];
 
 	_mixer->playVorbis(handle, _file, size);
 }
@@ -430,10 +434,7 @@
 				warning("playVoice: Can't load voice file %s", filename);
 				return;
 			} 
-			// FIXME freeing voice at this point causes frequent game crashes
-			// Maybe related to sound effects and speech using same sound format ?
-			// In any case, this means we currently leak.
-			// delete _voice;
+			delete _voice;
 			_voice = new WavSound(_mixer, file, _offsets);
 		}
 	}





More information about the Scummvm-git-logs mailing list