From bbccf76b4584eca741867f9a6ed89abe1bf48a85 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 24 Oct 2009 07:09:44 -0700 Subject: [PATCH] Dereference left over buffers and slots when sources are released --- OpenAL32/alSource.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 6d5e1dd9..d339d061 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -2150,10 +2150,31 @@ static ALint GetByteOffset(ALsource *pSource) ALvoid ReleaseALSources(ALCcontext *Context) { + ALuint j; + while(Context->Source) { ALsource *temp = Context->Source; - Context->Source = Context->Source->next; + Context->Source = temp->next; + + // For each buffer in the source's queue, decrement its reference counter and remove it + while(temp->queue != NULL) + { + ALbufferlistitem *ALBufferList = temp->queue; + // Decrement buffer's reference counter + if(ALBufferList->buffer != NULL) + ALBufferList->buffer->refcount--; + // Update queue to point to next element in list + temp->queue = ALBufferList->next; + // Release memory allocated for buffer list item + free(ALBufferList); + } + + for(j = 0;j < MAX_SENDS;++j) + { + if(temp->Send[j].Slot) + temp->Send[j].Slot->refcount--; + } // Release source structure ALTHUNK_REMOVEENTRY(temp->source);