Avoid calling alDelete* from alGen*

This commit is contained in:
Chris Robinson 2010-03-20 21:38:05 -07:00
parent 27358c8ce8
commit 99f28f25b0
6 changed files with 70 additions and 14 deletions

View File

@ -40,7 +40,7 @@ DECL_VERIFIER(Effect, ALeffect, effect)
ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
{
ALCcontext *Context;
ALsizei i, j;
ALsizei i=0, j;
Context = GetContextSuspended();
if(!Context) return;
@ -54,11 +54,12 @@ ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
// Check that enough memory has been allocted in the 'effectslots' array for n Effect Slots
if (!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint)))
{
ALeffectslot *end;
ALeffectslot **list = &Context->EffectSlotList;
while(*list)
list = &(*list)->next;
i = 0;
end = *list;
while(i < n)
{
*list = calloc(1, sizeof(ALeffectslot));
@ -66,7 +67,16 @@ ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
{
// We must have run out or memory
free(*list); *list = NULL;
alDeleteAuxiliaryEffectSlots(i, effectslots);
while(end->next)
{
ALeffectslot *temp = end->next;
end->next = temp->next;
ALEffect_Destroy(temp->EffectState);
ALTHUNK_REMOVEENTRY(temp->effectslot);
Context->EffectSlotCount--;
free(temp);
}
alSetError(Context, AL_OUT_OF_MEMORY);
break;
}

View File

@ -120,17 +120,27 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers)
// Check the pointer is valid (and points to enough memory to store Buffer Names)
if (!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
{
ALbuffer *end;
ALbuffer **list = &device->BufferList;
while(*list)
list = &(*list)->next;
// Create all the new Buffers
end = *list;
while(i < n)
{
*list = calloc(1, sizeof(ALbuffer));
if(!(*list))
{
alDeleteBuffers(i, puiBuffers);
while(end->next)
{
ALbuffer *temp = end->next;
end->next = temp->next;
ALTHUNK_REMOVEENTRY(temp->buffer);
device->BufferCount--;
free(temp);
}
alSetError(Context, AL_OUT_OF_MEMORY);
break;
}

View File

@ -56,17 +56,27 @@ ALvoid AL_APIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers)
* Databuffer Names) */
if(!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
{
ALdatabuffer *end;
ALdatabuffer **list = &device->DatabufferList;
while(*list)
list = &(*list)->next;
/* Create all the new Databuffers */
end = *list;
while(i < n)
{
*list = calloc(1, sizeof(ALdatabuffer));
if(!(*list))
{
alDeleteDatabuffersEXT(i, puiBuffers);
while(end->next)
{
ALdatabuffer *temp = end->next;
end->next = temp->next;
ALTHUNK_REMOVEENTRY(temp->databuffer);
device->DatabufferCount--;
free(temp);
}
alSetError(Context, AL_OUT_OF_MEMORY);
break;
}

View File

@ -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;
}

View File

@ -37,7 +37,7 @@ DECL_VERIFIER(Filter, ALfilter, filter)
ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
ALCcontext *Context;
ALsizei i;
ALsizei i=0;
Context = GetContextSuspended();
if(!Context) return;
@ -49,18 +49,26 @@ ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
// Check that enough memory has been allocted in the 'filters' array for n Filters
if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
{
ALfilter *end;
ALfilter **list = &device->FilterList;
while(*list)
list = &(*list)->next;
i = 0;
end = *list;
while(i < n)
{
*list = calloc(1, sizeof(ALfilter));
if(!(*list))
{
// We must have run out or memory
alDeleteFilters(i, filters);
while(end->next)
{
ALfilter *temp = end->next;
end->next = temp->next;
ALTHUNK_REMOVEENTRY(temp->filter);
device->FilterCount--;
free(temp);
}
alSetError(Context, AL_OUT_OF_MEMORY);
break;
}

View File

@ -61,17 +61,27 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n,ALuint *sources)
// Check that the requested number of sources can be generated
if((Context->SourceCount + n) <= Device->MaxNoOfSources)
{
ALsource *end;
ALsource **list = &Context->SourceList;
while(*list)
list = &(*list)->next;
// Add additional sources to the list (Source->next points to the location for the next Source structure)
end = *list;
while(i < n)
{
*list = calloc(1, sizeof(ALsource));
if(!(*list))
{
alDeleteSources(i, sources);
while(end->next)
{
ALsource *temp = end->next;
end->next = temp->next;
ALTHUNK_REMOVEENTRY(temp->source);
Context->SourceCount--;
free(temp);
}
alSetError(Context, AL_OUT_OF_MEMORY);
break;
}