# HG changeset patch # User Ryan C. Gordon # Date 1006749211 0 # Node ID 82acaa7107c277552b8ea23c899162e38d5bc6bd # Parent d8904267d23c2ab2f930ad2b4315f646b5fada23 Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust. diff -r d8904267d23c -r 82acaa7107c2 SDL_sound.c --- a/SDL_sound.c Mon Nov 26 04:32:55 2001 +0000 +++ b/SDL_sound.c Mon Nov 26 04:33:31 2001 +0000 @@ -568,12 +568,15 @@ /* nuke it... */ if (internal->rw != NULL) /* this condition is a "just in case" thing. */ SDL_RWclose(internal->rw); - assert(internal->buffer != NULL); - if (internal->buffer != sample->buffer) + + if ((internal->buffer != NULL) && (internal->buffer != sample->buffer)) free(internal->buffer); + free(internal); + if (sample->buffer != NULL) free(sample->buffer); + free(sample); } /* Sound_FreeSample */ @@ -635,6 +638,7 @@ { Sound_SampleInternal *internal = NULL; void *buf = NULL; + void *ptr; Uint32 newBufSize = 0; BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); @@ -644,7 +648,7 @@ while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) && ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) ) { - void *ptr = realloc(buf, newBufSize + sample->buffer_size); + ptr = realloc(buf, newBufSize + sample->buffer_size); if (ptr == NULL) { sample->flags |= SOUND_SAMPLEFLAG_ERROR; @@ -652,21 +656,26 @@ } /* if */ else { - Uint32 br = Sound_Decode(sample); + Uint32 br; + buf = ptr; + br = Sound_Decode(sample); memcpy( ((char *) buf) + newBufSize, sample->buffer, br ); newBufSize += br; } /* else */ } /* while */ + if (internal->buffer != sample->buffer) + free(internal->buffer); + free(sample->buffer); - sample->buffer = internal->buffer = internal->sdlcvt.buf = buf; + + internal->sdlcvt.buf = internal->buffer = sample->buffer = buf; sample->buffer_size = newBufSize; internal->buffer_size = newBufSize / internal->sdlcvt.len_mult; - internal->sdlcvt.len_mult = internal->buffer_size; + internal->sdlcvt.len = internal->buffer_size; return(newBufSize); } /* Sound_DecodeAll */ - /* end of SDL_sound.c ... */