From 8c212b2b52b6ec0c01dc3bf5e28fd17f070a0c8d Mon Sep 17 00:00:00 2001 From: meep-eep Date: Sat, 7 Dec 2002 19:07:27 +0000 Subject: [PATCH] Abaddon's malloc changes I thought I committed already. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@372 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/getopt/getopt.c | 4 ++-- sc2/src/sc2code/libs/graphics/sdl/rotozoom.c | 8 ++++---- sc2/src/sc2code/libs/memory/w_memlib.c | 12 +++++++++++- .../libs/sound/openal/decoders/decoder.c | 18 +++++++++--------- .../openal/decoders/mikmod/mikmod_internals.h | 2 +- .../sc2code/libs/sound/openal/decoders/wav.c | 2 +- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/sc2/src/getopt/getopt.c b/sc2/src/getopt/getopt.c index 6d57ba533..b38c76d01 100644 --- a/sc2/src/getopt/getopt.c +++ b/sc2/src/getopt/getopt.c @@ -322,7 +322,7 @@ exchange (argv) { /* We must extend the array. The user plays games with us and presents new arguments. */ - char *new_str = malloc (top + 1); + char *new_str = HMalloc (top + 1); if (new_str == NULL) nonoption_flags_len = nonoption_flags_max_len = 0; else @@ -434,7 +434,7 @@ _getopt_initialize (argc, argv, optstring) if (nonoption_flags_max_len < argc) nonoption_flags_max_len = argc; __getopt_nonoption_flags = - (char *) malloc (nonoption_flags_max_len); + (char *) HMalloc (nonoption_flags_max_len); if (__getopt_nonoption_flags == NULL) nonoption_flags_max_len = -1; else diff --git a/sc2/src/sc2code/libs/graphics/sdl/rotozoom.c b/sc2/src/sc2code/libs/graphics/sdl/rotozoom.c index 161166eb0..dde01ee2a 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/rotozoom.c +++ b/sc2/src/sc2code/libs/graphics/sdl/rotozoom.c @@ -52,10 +52,10 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth) /* * Allocate memory for row increments */ - if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) { + if ((sax = (int *) HMalloc((dst->w + 1) * sizeof(Uint32))) == NULL) { return (-1); } - if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) { + if ((say = (int *) HMalloc((dst->h + 1) * sizeof(Uint32))) == NULL) { free(sax); return (-1); } @@ -227,10 +227,10 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst) /* * Allocate memory for row increments */ - if ((sax = (Uint32 *) malloc(dst->w * sizeof(Uint32))) == NULL) { + if ((sax = (Uint32 *) HMalloc(dst->w * sizeof(Uint32))) == NULL) { return (-1); } - if ((say = (Uint32 *) malloc(dst->h * sizeof(Uint32))) == NULL) { + if ((say = (Uint32 *) HMalloc(dst->h * sizeof(Uint32))) == NULL) { if (sax != NULL) { free(sax); } diff --git a/sc2/src/sc2code/libs/memory/w_memlib.c b/sc2/src/sc2code/libs/memory/w_memlib.c index 4afa91539..e2b2c93c2 100644 --- a/sc2/src/sc2code/libs/memory/w_memlib.c +++ b/sc2/src/sc2code/libs/memory/w_memlib.c @@ -606,9 +606,19 @@ _alloc_mem (int size) void * HMalloc (int size) { + void *p; + if (size == 0) return (0); - return (_alloc_mem (size)); + if ((p = _alloc_mem(size)) == NULL) { + fprintf(stderr, "Fatal Error: HMalloc(): out of memory.\n"); +#ifdef DEBUG + abort(); +#else + exit(1); +#endif /* #ifdef DEBUG */ + } + return (p); } void diff --git a/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c b/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c index c684d6fd5..67a5650de 100644 --- a/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c +++ b/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c @@ -138,7 +138,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) //fprintf (stderr, "SoundDecoder_Load(): %s interpreted as wav\n", filename); - decoder = (TFB_SoundDecoder *) malloc (sizeof (TFB_SoundDecoder)); + decoder = (TFB_SoundDecoder *) HMalloc (sizeof (TFB_SoundDecoder)); decoder->buffer = NULL; decoder->buffer_size = 0; decoder->format = 0; @@ -148,7 +148,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) decoder->length = 0; // FIXME should be calculated decoder->decoder_info = decoder_info_wav; decoder->type = SOUNDDECODER_WAV; - decoder->filename = (char *) malloc (strlen (filename) + 1); + decoder->filename = (char *) HMalloc (strlen (filename) + 1); strcpy (decoder->filename, filename); return decoder; @@ -172,8 +172,8 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) mod->wrap = 0; mod->loop = 0; - decoder = (TFB_SoundDecoder *) malloc (sizeof (TFB_SoundDecoder)); - decoder->buffer = malloc (buffer_size); + decoder = (TFB_SoundDecoder *) HMalloc (sizeof (TFB_SoundDecoder)); + decoder->buffer = HMalloc (buffer_size); decoder->buffer_size = buffer_size; decoder->format = AL_FORMAT_STEREO16; decoder->frequency = md_mixfreq; @@ -182,7 +182,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) decoder->length = 0; // FIXME way to obtain this from mikmod? decoder->decoder_info = decoder_info_mod; decoder->type = SOUNDDECODER_MOD; - decoder->filename = (char *) malloc (strlen (filename) + 1); + decoder->filename = (char *) HMalloc (strlen (filename) + 1); strcpy (decoder->filename, filename); decoder->data = mod; @@ -198,7 +198,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) //fprintf (stderr, "SoundDecoder_Load(): %s interpreted as ogg\n", filename); - vf = (OggVorbis_File *) malloc (sizeof (OggVorbis_File)); + vf = (OggVorbis_File *) HMalloc (sizeof (OggVorbis_File)); if (!vf) { fprintf (stderr, "SoundDecoder_Load(): couldn't allocate mem for OggVorbis_File\n"); @@ -235,8 +235,8 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) //fprintf (stderr, "SoundDecoder_Load(): ogg bitstream version %d, channels %d, rate %d, length %.2f seconds\n", vinfo->version, vinfo->channels, vinfo->rate, ov_time_total (vf, -1)); - decoder = (TFB_SoundDecoder *) malloc (sizeof (TFB_SoundDecoder)); - decoder->buffer = malloc (buffer_size); + decoder = (TFB_SoundDecoder *) HMalloc (sizeof (TFB_SoundDecoder)); + decoder->buffer = HMalloc (buffer_size); decoder->buffer_size = buffer_size; if (vinfo->channels == 1) decoder->format = AL_FORMAT_MONO16; @@ -248,7 +248,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) decoder->length = (float) ov_time_total (vf, -1); decoder->decoder_info = decoder_info_ogg; decoder->type = SOUNDDECODER_OGG; - decoder->filename = (char *) malloc (strlen (filename) + 1); + decoder->filename = (char *) HMalloc (strlen (filename) + 1); strcpy (decoder->filename, filename); decoder->data = vf; diff --git a/sc2/src/sc2code/libs/sound/openal/decoders/mikmod/mikmod_internals.h b/sc2/src/sc2code/libs/sound/openal/decoders/mikmod/mikmod_internals.h index d33d4f01c..4edee282c 100644 --- a/sc2/src/sc2code/libs/sound/openal/decoders/mikmod/mikmod_internals.h +++ b/sc2/src/sc2code/libs/sound/openal/decoders/mikmod/mikmod_internals.h @@ -47,7 +47,7 @@ static char *strdup(const char *str) { char *newstr; - newstr = (char *)malloc(strlen(str)+1); + newstr = (char *)HMalloc(strlen(str)+1); if ( newstr != NULL ) { strcpy(newstr, str); } diff --git a/sc2/src/sc2code/libs/sound/openal/decoders/wav.c b/sc2/src/sc2code/libs/sound/openal/decoders/wav.c index c868aa04e..d8fc80534 100644 --- a/sc2/src/sc2code/libs/sound/openal/decoders/wav.c +++ b/sc2/src/sc2code/libs/sound/openal/decoders/wav.c @@ -146,7 +146,7 @@ void LoadWAVFile (ALbyte *file, ALenum *format, ALvoid **data, ALsizei *size, AL if (FmtHdr.Format==0x0001) { *size=ChunkHdr.Size; - *data=malloc(ChunkHdr.Size+31); + *data=HMalloc(ChunkHdr.Size+31); if (*data) fread(*data,FmtHdr.BlockAlign,ChunkHdr.Size/FmtHdr.BlockAlign,Stream); memset(((char *)*data)+ChunkHdr.Size,0,31); }