aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlyssa Milburn2011-01-02 14:57:20 +0000
committerAlyssa Milburn2011-01-02 14:57:20 +0000
commit940e4f936eac2aecb6b422e3809082835be4e4e9 (patch)
tree1c4bfca65a49c76612f5bcd4b3c5551db71d7d9e
parent1f579add9fdb98015e30a4c39026f5fca517e1b2 (diff)
downloadscummvm-rg350-940e4f936eac2aecb6b422e3809082835be4e4e9.tar.gz
scummvm-rg350-940e4f936eac2aecb6b422e3809082835be4e4e9.tar.bz2
scummvm-rg350-940e4f936eac2aecb6b422e3809082835be4e4e9.zip
MOHAWK: Don't leak the MIDI data.
svn-id: r55094
-rw-r--r--engines/mohawk/sound.cpp15
-rw-r--r--engines/mohawk/sound.h1
2 files changed, 12 insertions, 4 deletions
diff --git a/engines/mohawk/sound.cpp b/engines/mohawk/sound.cpp
index 77028e1604..fd56d922c8 100644
--- a/engines/mohawk/sound.cpp
+++ b/engines/mohawk/sound.cpp
@@ -38,6 +38,7 @@ namespace Mohawk {
Sound::Sound(MohawkEngine* vm) : _vm(vm) {
_midiDriver = NULL;
_midiParser = NULL;
+ _midiData = NULL;
initMidi();
}
@@ -54,6 +55,9 @@ Sound::~Sound() {
_midiDriver->close();
delete _midiDriver;
}
+
+ if (_midiData)
+ delete[] _midiData;
}
void Sound::initMidi() {
@@ -160,6 +164,9 @@ void Sound::playMidi(uint16 id) {
assert(_midiDriver && _midiParser);
_midiParser->unloadMusic();
+ if (_midiData)
+ delete[] _midiData;
+
Common::SeekableReadStream *midi = _vm->getResource(ID_TMID, id);
idTag = midi->readUint32BE();
@@ -168,10 +175,10 @@ void Sound::playMidi(uint16 id) {
idTag = midi->readUint32BE();
assert(idTag == ID_MIDI);
- byte *midiData = (byte *)malloc(midi->size() - 12); // Enough to cover MThd/Prg#/MTrk
+ _midiData = new byte[midi->size() - 12]; // Enough to cover MThd/Prg#/MTrk
// Read the MThd Data
- midi->read(midiData, 14);
+ midi->read(_midiData, 14);
// TODO: Load patches from the Prg# section... skip it for now.
idTag = midi->readUint32BE();
@@ -180,12 +187,12 @@ void Sound::playMidi(uint16 id) {
// Read the MTrk Data
uint32 mtrkSize = midi->size() - midi->pos();
- midi->read(midiData + 14, mtrkSize);
+ midi->read(_midiData + 14, mtrkSize);
delete midi;
// Now, play it :)
- if (!_midiParser->loadMusic(midiData, 14 + mtrkSize))
+ if (!_midiParser->loadMusic(_midiData, 14 + mtrkSize))
error ("Could not play MIDI music from tMID %04x\n", id);
_midiDriver->setTimerCallback(_midiParser, MidiParser::timerCallback);
diff --git a/engines/mohawk/sound.h b/engines/mohawk/sound.h
index 3c16939556..6c1fd5aa0b 100644
--- a/engines/mohawk/sound.h
+++ b/engines/mohawk/sound.h
@@ -149,6 +149,7 @@ private:
MohawkEngine *_vm;
MidiDriver *_midiDriver;
MidiParser *_midiParser;
+ byte *_midiData;
static Audio::AudioStream *makeMohawkWaveStream(Common::SeekableReadStream *stream);
static Audio::AudioStream *makeOldMohawkWaveStream(Common::SeekableReadStream *stream);