SCUMM: (MI1/Mac) - fix mem leak

This commit is contained in:
athrxx 2024-06-15 15:24:06 +02:00
parent 6fb06a0bbc
commit a679820502

View File

@ -40,6 +40,8 @@ namespace Scumm {
class MacSndChannel {
public:
MacSndChannel(MacLowLevelPCMDriver *drv, Audio::Mixer::SoundType sndtp, int synth, bool interp, bool enableL, bool enableR, MacLowLevelPCMDriver::ChanCallback *callback);
~MacSndChannel();
MacLowLevelPCMDriver::ChanHandle getHandle() const;
void playSamples(const MacLowLevelPCMDriver::PCMSound *snd);
@ -515,6 +517,10 @@ MacSndChannel::MacSndChannel(MacLowLevelPCMDriver *drv, Audio::Mixer::SoundType
}
}
MacSndChannel::~MacSndChannel() {
flush();
}
MacLowLevelPCMDriver::ChanHandle MacSndChannel::getHandle() const {
const void *ptr = this;
return *reinterpret_cast<const int*>(&ptr);
@ -557,6 +563,12 @@ void MacSndChannel::wait(uint32 duration) {
}
void MacSndChannel::flush() {
for (Common::Array<SoundCommand>::const_iterator i = _sndCmdQueue.begin(); i != _sndCmdQueue.end(); ++i) {
if (i->ptr && i->arg2 == 1)
delete reinterpret_cast<MacLowLevelPCMDriver::PCMSound*>(i->ptr);
else if (i->ptr && i->arg2 == 2)
delete[] reinterpret_cast<byte*>(i->ptr);
}
_sndCmdQueue.clear();
_tmrInc = 0;
_duration = 0;