aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Kiehl2004-01-19 17:46:08 +0000
committerOliver Kiehl2004-01-19 17:46:08 +0000
commit7080232de0cbc40f4300d125db0e39c7a8dace02 (patch)
treee7469b3baf3be647327a2d1cc092848de3fc1ede
parent18799981aa8cba6e2fc5a1ed3127daeeb1881505 (diff)
downloadscummvm-rg350-7080232de0cbc40f4300d125db0e39c7a8dace02.tar.gz
scummvm-rg350-7080232de0cbc40f4300d125db0e39c7a8dace02.tar.bz2
scummvm-rg350-7080232de0cbc40f4300d125db0e39c7a8dace02.zip
fix memory leak
svn-id: r12510
-rw-r--r--simon/sound.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/simon/sound.cpp b/simon/sound.cpp
index 1fca707b40..205094343f 100644
--- a/simon/sound.cpp
+++ b/simon/sound.cpp
@@ -32,6 +32,7 @@ protected:
File *_file;
uint32 *_offsets;
SoundMixer *_mixer;
+ bool _freeOffsets;
public:
BaseSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false);
@@ -74,6 +75,7 @@ BaseSound::BaseSound(SoundMixer *mixer, File *file, uint32 base, bool bigendian)
res = size / sizeof(uint32);
_offsets = (uint32 *)malloc(size + sizeof(uint32));
+ _freeOffsets = true;
_file->seek(base, SEEK_SET);
@@ -99,10 +101,12 @@ BaseSound::BaseSound(SoundMixer *mixer, File *file, uint32 *offsets, bool bigend
_mixer = mixer;
_file = file;
_offsets = offsets;
+ _freeOffsets = false;
}
BaseSound::~BaseSound() {
- free(_offsets);
+ if (_freeOffsets)
+ free(_offsets);
delete _file;
}
@@ -231,7 +235,7 @@ void VorbisSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
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 @@ void Sound::playVoice(uint sound) {
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);
}
}