From 99f28f25b07e28415ce58fd552dcadf2a187c3e3 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Sat, 20 Mar 2010 21:38:05 -0700
Subject: Avoid calling alDelete* from alGen*

---
 OpenAL32/alEffect.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

(limited to 'OpenAL32/alEffect.c')

diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c
index 7241de2c..a63ea72e 100644
--- a/OpenAL32/alEffect.c
+++ b/OpenAL32/alEffect.c
@@ -41,7 +41,7 @@ DECL_VERIFIER(Effect, ALeffect, effect)
 ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
 {
     ALCcontext *Context;
-    ALsizei i;
+    ALsizei i=0;
 
     Context = GetContextSuspended();
     if(!Context) return;
@@ -53,18 +53,26 @@ ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
         // Check that enough memory has been allocted in the 'effects' array for n Effects
         if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint)))
         {
+            ALeffect *end;
             ALeffect **list = &device->EffectList;
             while(*list)
                 list = &(*list)->next;
 
-            i = 0;
+            end = *list;
             while(i < n)
             {
                 *list = calloc(1, sizeof(ALeffect));
                 if(!(*list))
                 {
-                    // We must have run out or memory
-                    alDeleteEffects(i, effects);
+                    while(end->next)
+                    {
+                        ALeffect *temp = end->next;
+                        end->next = temp->next;
+
+                        ALTHUNK_REMOVEENTRY(temp->effect);
+                        device->EffectCount--;
+                        free(temp);
+                    }
                     alSetError(Context, AL_OUT_OF_MEMORY);
                     break;
                 }
-- 
cgit v1.2.3