changeset 11938:01f75baf4cdf draft

(svn r16341) -Codechange: just use a static array instead of a never freed malloc
author rubidium <rubidium@openttd.org>
date Sun, 17 May 2009 17:48:05 +0000
parents 58cf1ef548bb
children 577d93a5e10d
files src/sound.cpp
diffstat 1 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -13,7 +13,7 @@
 #include "vehicle_base.h"
 #include "debug.h"
 
-static FileEntry *_files;
+static FileEntry _original_sounds[ORIGINAL_SAMPLE_COUNT];
 MusicFileSettings msf;
 
 /* Number of levels of panning per side */
@@ -21,8 +21,7 @@
 
 static void OpenBankFile(const char *filename)
 {
-	FileEntry *fe = CallocT<FileEntry>(ORIGINAL_SAMPLE_COUNT);
-	_files = fe;
+	memset(_original_sounds, 0, sizeof(_original_sounds));
 
 	FioOpenFile(SOUND_SLOT, filename);
 	size_t pos = FioGetPos();
@@ -40,12 +39,13 @@
 	FioSeekTo(pos, SEEK_SET);
 
 	for (uint i = 0; i != ORIGINAL_SAMPLE_COUNT; i++) {
-		fe[i].file_slot = SOUND_SLOT;
-		fe[i].file_offset = FioReadDword() + pos;
-		fe[i].file_size = FioReadDword();
+		_original_sounds[i].file_slot = SOUND_SLOT;
+		_original_sounds[i].file_offset = FioReadDword() + pos;
+		_original_sounds[i].file_size = FioReadDword();
 	}
 
-	for (uint i = 0; i != ORIGINAL_SAMPLE_COUNT; i++, fe++) {
+	for (uint i = 0; i != ORIGINAL_SAMPLE_COUNT; i++) {
+		FileEntry *fe = &_original_sounds[i];
 		char name[255];
 
 		FioSeekTo(fe->file_offset, SEEK_SET);
@@ -178,10 +178,9 @@
 void SndCopyToPool()
 {
 	for (uint i = 0; i < ORIGINAL_SAMPLE_COUNT; i++) {
-		FileEntry *orig = &_files[_sound_idx[i]];
 		FileEntry *fe = AllocateFileEntry();
 
-		*fe = *orig;
+		*fe = _original_sounds[_sound_idx[i]];
 		fe->volume = _sound_base_vol[i];
 		fe->priority = 0;
 	}