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
This commit is contained in:
meep-eep
2002-12-07 19:07:27 +00:00
parent 51f28d7537
commit 8c212b2b52
6 changed files with 28 additions and 18 deletions
+2 -2
View File
@@ -322,7 +322,7 @@ exchange (argv)
{ {
/* We must extend the array. The user plays games with us and /* We must extend the array. The user plays games with us and
presents new arguments. */ presents new arguments. */
char *new_str = malloc (top + 1); char *new_str = HMalloc (top + 1);
if (new_str == NULL) if (new_str == NULL)
nonoption_flags_len = nonoption_flags_max_len = 0; nonoption_flags_len = nonoption_flags_max_len = 0;
else else
@@ -434,7 +434,7 @@ _getopt_initialize (argc, argv, optstring)
if (nonoption_flags_max_len < argc) if (nonoption_flags_max_len < argc)
nonoption_flags_max_len = argc; nonoption_flags_max_len = argc;
__getopt_nonoption_flags = __getopt_nonoption_flags =
(char *) malloc (nonoption_flags_max_len); (char *) HMalloc (nonoption_flags_max_len);
if (__getopt_nonoption_flags == NULL) if (__getopt_nonoption_flags == NULL)
nonoption_flags_max_len = -1; nonoption_flags_max_len = -1;
else else
+4 -4
View File
@@ -52,10 +52,10 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
/* /*
* Allocate memory for row increments * 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); return (-1);
} }
if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) { if ((say = (int *) HMalloc((dst->h + 1) * sizeof(Uint32))) == NULL) {
free(sax); free(sax);
return (-1); return (-1);
} }
@@ -227,10 +227,10 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst)
/* /*
* Allocate memory for row increments * 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); return (-1);
} }
if ((say = (Uint32 *) malloc(dst->h * sizeof(Uint32))) == NULL) { if ((say = (Uint32 *) HMalloc(dst->h * sizeof(Uint32))) == NULL) {
if (sax != NULL) { if (sax != NULL) {
free(sax); free(sax);
} }
+11 -1
View File
@@ -606,9 +606,19 @@ _alloc_mem (int size)
void * void *
HMalloc (int size) HMalloc (int size)
{ {
void *p;
if (size == 0) return (0); 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 void
@@ -138,7 +138,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size)
//fprintf (stderr, "SoundDecoder_Load(): %s interpreted as wav\n", filename); //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 = NULL;
decoder->buffer_size = 0; decoder->buffer_size = 0;
decoder->format = 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->length = 0; // FIXME should be calculated
decoder->decoder_info = decoder_info_wav; decoder->decoder_info = decoder_info_wav;
decoder->type = SOUNDDECODER_WAV; decoder->type = SOUNDDECODER_WAV;
decoder->filename = (char *) malloc (strlen (filename) + 1); decoder->filename = (char *) HMalloc (strlen (filename) + 1);
strcpy (decoder->filename, filename); strcpy (decoder->filename, filename);
return decoder; return decoder;
@@ -172,8 +172,8 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size)
mod->wrap = 0; mod->wrap = 0;
mod->loop = 0; mod->loop = 0;
decoder = (TFB_SoundDecoder *) malloc (sizeof (TFB_SoundDecoder)); decoder = (TFB_SoundDecoder *) HMalloc (sizeof (TFB_SoundDecoder));
decoder->buffer = malloc (buffer_size); decoder->buffer = HMalloc (buffer_size);
decoder->buffer_size = buffer_size; decoder->buffer_size = buffer_size;
decoder->format = AL_FORMAT_STEREO16; decoder->format = AL_FORMAT_STEREO16;
decoder->frequency = md_mixfreq; 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->length = 0; // FIXME way to obtain this from mikmod?
decoder->decoder_info = decoder_info_mod; decoder->decoder_info = decoder_info_mod;
decoder->type = SOUNDDECODER_MOD; decoder->type = SOUNDDECODER_MOD;
decoder->filename = (char *) malloc (strlen (filename) + 1); decoder->filename = (char *) HMalloc (strlen (filename) + 1);
strcpy (decoder->filename, filename); strcpy (decoder->filename, filename);
decoder->data = mod; 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); //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) if (!vf)
{ {
fprintf (stderr, "SoundDecoder_Load(): couldn't allocate mem for OggVorbis_File\n"); 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)); //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 = (TFB_SoundDecoder *) HMalloc (sizeof (TFB_SoundDecoder));
decoder->buffer = malloc (buffer_size); decoder->buffer = HMalloc (buffer_size);
decoder->buffer_size = buffer_size; decoder->buffer_size = buffer_size;
if (vinfo->channels == 1) if (vinfo->channels == 1)
decoder->format = AL_FORMAT_MONO16; 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->length = (float) ov_time_total (vf, -1);
decoder->decoder_info = decoder_info_ogg; decoder->decoder_info = decoder_info_ogg;
decoder->type = SOUNDDECODER_OGG; decoder->type = SOUNDDECODER_OGG;
decoder->filename = (char *) malloc (strlen (filename) + 1); decoder->filename = (char *) HMalloc (strlen (filename) + 1);
strcpy (decoder->filename, filename); strcpy (decoder->filename, filename);
decoder->data = vf; decoder->data = vf;
@@ -47,7 +47,7 @@ static char *strdup(const char *str)
{ {
char *newstr; char *newstr;
newstr = (char *)malloc(strlen(str)+1); newstr = (char *)HMalloc(strlen(str)+1);
if ( newstr != NULL ) { if ( newstr != NULL ) {
strcpy(newstr, str); strcpy(newstr, str);
} }
@@ -146,7 +146,7 @@ void LoadWAVFile (ALbyte *file, ALenum *format, ALvoid **data, ALsizei *size, AL
if (FmtHdr.Format==0x0001) if (FmtHdr.Format==0x0001)
{ {
*size=ChunkHdr.Size; *size=ChunkHdr.Size;
*data=malloc(ChunkHdr.Size+31); *data=HMalloc(ChunkHdr.Size+31);
if (*data) fread(*data,FmtHdr.BlockAlign,ChunkHdr.Size/FmtHdr.BlockAlign,Stream); if (*data) fread(*data,FmtHdr.BlockAlign,ChunkHdr.Size/FmtHdr.BlockAlign,Stream);
memset(((char *)*data)+ChunkHdr.Size,0,31); memset(((char *)*data)+ChunkHdr.Size,0,31);
} }