Mercurial > SDL_sound_CoreAudio
changeset 167:82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 26 Nov 2001 04:33:31 +0000 |
parents | d8904267d23c |
children | 87b00f023710 |
files | SDL_sound.c |
diffstat | 1 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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 ... */