From d8e50b8a037de7f721491664610682f1076ca9ea Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 22 Oct 2011 19:37:49 +0200 Subject: KYRA: Fix memory leak when a sound is started but no free handles are left. --- engines/kyra/sound.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index b4fcea784e..0e83c1cb1f 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -109,8 +109,14 @@ bool Sound::playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *hand while (h < kNumChannelHandles && _mixer->isSoundHandleActive(_soundChannels[h])) ++h; - if (h >= kNumChannelHandles) + if (h >= kNumChannelHandles) { + // When we run out of handles we need to destroy the stream object, + // this is to avoid memory leaks in some scenes where too many sfx + // are started. + // See bug #3427240 "LOL-CD: Memory leak in caves level 3". + delete stream; return false; + } _mixer->playStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h], stream, -1, volume); if (handle) -- cgit v1.2.3