aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2012-07-08 22:15:40 +0200
committerSven Hesse2012-07-30 01:44:46 +0200
commit3189729c972b5da1356497e82e08a21c94c8fbec (patch)
tree5308295aa7825593f1c740b04beb2db8e8c2d43b
parent850472f21e73280c0bf35c76163419a7e280fea2 (diff)
downloadscummvm-rg350-3189729c972b5da1356497e82e08a21c94c8fbec.tar.gz
scummvm-rg350-3189729c972b5da1356497e82e08a21c94c8fbec.tar.bz2
scummvm-rg350-3189729c972b5da1356497e82e08a21c94c8fbec.zip
GOB: Don't leak in sampleLoad() when loading fails
-rw-r--r--engines/gob/sound/sound.cpp11
-rw-r--r--engines/gob/sound/sound.h2
2 files changed, 8 insertions, 5 deletions
diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp
index 69a668e5fb..63af6aeef4 100644
--- a/engines/gob/sound/sound.cpp
+++ b/engines/gob/sound/sound.cpp
@@ -109,7 +109,7 @@ int Sound::sampleGetNextFreeSlot() const {
return -1;
}
-bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName, bool tryExist) {
+bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName) {
if (!sndDesc)
return false;
@@ -117,12 +117,15 @@ bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName,
int32 size;
byte *data = _vm->_dataIO->getFile(fileName, size);
- if (!data) {
- warning("Can't open sample file \"%s\"", fileName);
+
+ if (!data || !sndDesc->load(type, data, size)) {
+ delete data;
+
+ warning("Sound::sampleLoad(): Failed to load sound \"%s\"", fileName);
return false;
}
- return sndDesc->load(type, data, size);
+ return true;
}
void Sound::sampleFree(SoundDesc *sndDesc, bool noteAdLib, int index) {
diff --git a/engines/gob/sound/sound.h b/engines/gob/sound/sound.h
index 7beffb5dc7..bbc182d172 100644
--- a/engines/gob/sound/sound.h
+++ b/engines/gob/sound/sound.h
@@ -51,7 +51,7 @@ public:
const SoundDesc *sampleGetBySlot(int slot) const;
int sampleGetNextFreeSlot() const;
- bool sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName, bool tryExist = true);
+ bool sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName);
void sampleFree(SoundDesc *sndDesc, bool noteAdLib = false, int index = -1);