aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
authorTorbjörn Andersson2005-12-11 08:30:48 +0000
committerTorbjörn Andersson2005-12-11 08:30:48 +0000
commit7cbb9af1137a55f4b840ea980f5c6133f6697d4d (patch)
treeddfa31a542ff2080b58a82d0287bba26e51301ae /sword2
parent38c3df43933b18682ee0c78c9eb2a8e078f9ab64 (diff)
downloadscummvm-rg350-7cbb9af1137a55f4b840ea980f5c6133f6697d4d.tar.gz
scummvm-rg350-7cbb9af1137a55f4b840ea980f5c6133f6697d4d.tar.bz2
scummvm-rg350-7cbb9af1137a55f4b840ea980f5c6133f6697d4d.zip
Fixed Valgrind memory leak warnings, either by freeing memory on exit or
(in one case) by not allocating file handles dynamically. While this isn't really necessary at the moment, it makes it easier to find the real memory leaks, if there are any. svn-id: r19775
Diffstat (limited to 'sword2')
-rw-r--r--sword2/driver/d_sound.cpp42
-rw-r--r--sword2/resman.cpp2
-rw-r--r--sword2/sound.cpp13
-rw-r--r--sword2/sound.h2
4 files changed, 31 insertions, 28 deletions
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp
index 26495047d4..22e3bf1453 100644
--- a/sword2/driver/d_sound.cpp
+++ b/sword2/driver/d_sound.cpp
@@ -43,7 +43,7 @@ namespace Sword2 {
static AudioStream *makeCLUStream(Common::File *fp, int size);
static AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) {
- if (!fh->file->isOpen()) {
+ if (!fh->file.isOpen()) {
struct {
const char *ext;
int mode;
@@ -82,13 +82,13 @@ static AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd
if (soundMode == 0)
return NULL;
- fh->file->open(filename);
+ fh->file.open(filename);
fh->fileType = soundMode;
- if (!fh->file->isOpen()) {
+ if (!fh->file.isOpen()) {
warning("Very strange fopen error");
return NULL;
}
- if (fh->fileSize != fh->file->size()) {
+ if (fh->fileSize != fh->file.size()) {
if (fh->idxTab) {
free(fh->idxTab);
fh->idxTab = NULL;
@@ -99,19 +99,19 @@ static AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd
uint32 entrySize = (fh->fileType == kCLUMode) ? 2 : 3;
if (!fh->idxTab) {
- fh->file->seek(0);
- fh->idxLen = fh->file->readUint32LE();
- fh->file->seek(entrySize * 4);
+ fh->file.seek(0);
+ fh->idxLen = fh->file.readUint32LE();
+ fh->file.seek(entrySize * 4);
fh->idxTab = (uint32*)malloc(fh->idxLen * 3 * sizeof(uint32));
for (uint32 cnt = 0; cnt < fh->idxLen; cnt++) {
- fh->idxTab[cnt * 3 + 0] = fh->file->readUint32LE();
- fh->idxTab[cnt * 3 + 1] = fh->file->readUint32LE();
+ fh->idxTab[cnt * 3 + 0] = fh->file.readUint32LE();
+ fh->idxTab[cnt * 3 + 1] = fh->file.readUint32LE();
if (fh->fileType == kCLUMode) {
fh->idxTab[cnt * 3 + 2] = fh->idxTab[cnt * 3 + 1];
fh->idxTab[cnt * 3 + 1]--;
} else
- fh->idxTab[cnt * 3 + 2] = fh->file->readUint32LE();
+ fh->idxTab[cnt * 3 + 2] = fh->file.readUint32LE();
}
}
@@ -123,26 +123,26 @@ static AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd
*numSamples = len;
if (!pos || !len) {
- fh->file->close();
+ fh->file.close();
return NULL;
}
- fh->file->seek(pos, SEEK_SET);
+ fh->file.seek(pos, SEEK_SET);
switch (fh->fileType) {
case kCLUMode:
- return makeCLUStream(fh->file, enc_len);
+ return makeCLUStream(&fh->file, enc_len);
#ifdef USE_MAD
case kMP3Mode:
- return makeMP3Stream(fh->file, enc_len);
+ return makeMP3Stream(&fh->file, enc_len);
#endif
#ifdef USE_VORBIS
case kVorbisMode:
- return makeVorbisStream(fh->file, enc_len);
+ return makeVorbisStream(&fh->file, enc_len);
#endif
#ifdef USE_FLAC
case kFlacMode:
- return makeFlacStream(fh->file, enc_len);
+ return makeFlacStream(&fh->file, enc_len);
#endif
default:
return NULL;
@@ -461,8 +461,8 @@ int Sound::readBuffer(int16 *buffer, const int numSamples) {
}
for (i = 0; i < MAXMUS; i++) {
- if (!inUse[i] && !_musicFile[i].inUse && _musicFile[i].file->isOpen())
- _musicFile[i].file->close();
+ if (!inUse[i] && !_musicFile[i].inUse && _musicFile[i].file.isOpen())
+ _musicFile[i].file.close();
}
return numSamples;
@@ -470,7 +470,7 @@ int Sound::readBuffer(int16 *buffer, const int numSamples) {
bool Sound::endOfData() const {
for (int i = 0; i < MAXMUS; i++) {
- if (_musicFile[i].file->isOpen())
+ if (_musicFile[i].file.isOpen())
return false;
}
@@ -727,13 +727,13 @@ uint32 Sound::preFetchCompSpeech(uint32 speechId, uint16 **buf) {
*buf = (uint16 *)malloc(bufferSize);
if (!*buf) {
delete input;
- fh->file->close();
+ fh->file.close();
return 0;
}
uint32 readSamples = input->readBuffer((int16 *)*buf, numSamples);
- fh->file->close();
+ fh->file.close();
delete input;
return 2 * readSamples;
diff --git a/sword2/resman.cpp b/sword2/resman.cpp
index dfb6d1690e..8269f54c4a 100644
--- a/sword2/resman.cpp
+++ b/sword2/resman.cpp
@@ -189,6 +189,8 @@ ResourceManager::~ResourceManager() {
_vm->_memory->memFree(res->ptr);
res = res->next;
}
+ for (int i = 0; i < _totalClusters; i++)
+ free(_resFiles[i].entryTab);
free(_resList);
free(_resConvTable);
}
diff --git a/sword2/sound.cpp b/sword2/sound.cpp
index 0b673cb64f..de53400d42 100644
--- a/sword2/sound.cpp
+++ b/sword2/sound.cpp
@@ -53,14 +53,12 @@ Sound::Sound(Sword2Engine *vm) {
for (i = 0; i < MAXMUS; i++) {
_music[i] = NULL;
- _musicFile[i].file = new Common::File;
_musicFile[i].idxTab = NULL;
_musicFile[i].idxLen = 0;
_musicFile[i].fileSize = 0;
_musicFile[i].fileType = 0;
_musicFile[i].inUse = false;
- _speechFile[i].file = new Common::File;
_speechFile[i].idxTab = NULL;
_speechFile[i].idxLen = 0;
_speechFile[i].fileSize = 0;
@@ -96,10 +94,13 @@ Sound::~Sound() {
free(_mixBuffer);
for (int i = 0; i < MAXMUS; i++) {
- if (_musicFile[i].file->isOpen())
- _musicFile[i].file->close();
- if (_speechFile[i].file->isOpen())
- _speechFile[i].file->close();
+ if (_musicFile[i].file.isOpen())
+ _musicFile[i].file.close();
+ if (_speechFile[i].file.isOpen())
+ _speechFile[i].file.close();
+
+ free(_musicFile[i].idxTab);
+ free(_speechFile[i].idxTab);
}
}
diff --git a/sword2/sound.h b/sword2/sound.h
index 05ff4a43b7..60e31946bd 100644
--- a/sword2/sound.h
+++ b/sword2/sound.h
@@ -109,7 +109,7 @@ public:
};
struct SoundFileHandle {
- Common::File *file;
+ Common::File file;
uint32 *idxTab;
uint32 idxLen;
uint32 fileSize;