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) ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
{ {
ALCcontext *Context; ALCcontext *Context;
ALsizei i, j; ALsizei i=0, j;
Context = GetContextSuspended(); Context = GetContextSuspended();
if(!Context) return; 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 // Check that enough memory has been allocted in the 'effectslots' array for n Effect Slots
if (!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint))) if (!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint)))
{ {
ALeffectslot *end;
ALeffectslot **list = &Context->EffectSlotList; ALeffectslot **list = &Context->EffectSlotList;
while(*list) while(*list)
list = &(*list)->next; list = &(*list)->next;
i = 0; end = *list;
while(i < n) while(i < n)
{ {
*list = calloc(1, sizeof(ALeffectslot)); *list = calloc(1, sizeof(ALeffectslot));
@ -66,7 +67,16 @@ ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
{ {
// We must have run out or memory // We must have run out or memory
free(*list); *list = NULL; 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); alSetError(Context, AL_OUT_OF_MEMORY);
break; 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) // Check the pointer is valid (and points to enough memory to store Buffer Names)
if (!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint))) if (!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
{ {
ALbuffer *end;
ALbuffer **list = &device->BufferList; ALbuffer **list = &device->BufferList;
while(*list) while(*list)
list = &(*list)->next; list = &(*list)->next;
// Create all the new Buffers // Create all the new Buffers
end = *list;
while(i < n) while(i < n)
{ {
*list = calloc(1, sizeof(ALbuffer)); *list = calloc(1, sizeof(ALbuffer));
if(!(*list)) 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); alSetError(Context, AL_OUT_OF_MEMORY);
break; break;
} }

View File

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

View File

@ -41,7 +41,7 @@ DECL_VERIFIER(Effect, ALeffect, effect)
ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
{ {
ALCcontext *Context; ALCcontext *Context;
ALsizei i; ALsizei i=0;
Context = GetContextSuspended(); Context = GetContextSuspended();
if(!Context) return; 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 // Check that enough memory has been allocted in the 'effects' array for n Effects
if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint))) if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint)))
{ {
ALeffect *end;
ALeffect **list = &device->EffectList; ALeffect **list = &device->EffectList;
while(*list) while(*list)
list = &(*list)->next; list = &(*list)->next;
i = 0; end = *list;
while(i < n) while(i < n)
{ {
*list = calloc(1, sizeof(ALeffect)); *list = calloc(1, sizeof(ALeffect));
if(!(*list)) if(!(*list))
{ {
// We must have run out or memory while(end->next)
alDeleteEffects(i, effects); {
ALeffect *temp = end->next;
end->next = temp->next;
ALTHUNK_REMOVEENTRY(temp->effect);
device->EffectCount--;
free(temp);
}
alSetError(Context, AL_OUT_OF_MEMORY); alSetError(Context, AL_OUT_OF_MEMORY);
break; break;
} }

View File

@ -37,7 +37,7 @@ DECL_VERIFIER(Filter, ALfilter, filter)
ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{ {
ALCcontext *Context; ALCcontext *Context;
ALsizei i; ALsizei i=0;
Context = GetContextSuspended(); Context = GetContextSuspended();
if(!Context) return; 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 // Check that enough memory has been allocted in the 'filters' array for n Filters
if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint))) if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
{ {
ALfilter *end;
ALfilter **list = &device->FilterList; ALfilter **list = &device->FilterList;
while(*list) while(*list)
list = &(*list)->next; list = &(*list)->next;
i = 0; end = *list;
while(i < n) while(i < n)
{ {
*list = calloc(1, sizeof(ALfilter)); *list = calloc(1, sizeof(ALfilter));
if(!(*list)) if(!(*list))
{ {
// We must have run out or memory while(end->next)
alDeleteFilters(i, filters); {
ALfilter *temp = end->next;
end->next = temp->next;
ALTHUNK_REMOVEENTRY(temp->filter);
device->FilterCount--;
free(temp);
}
alSetError(Context, AL_OUT_OF_MEMORY); alSetError(Context, AL_OUT_OF_MEMORY);
break; 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 // Check that the requested number of sources can be generated
if((Context->SourceCount + n) <= Device->MaxNoOfSources) if((Context->SourceCount + n) <= Device->MaxNoOfSources)
{ {
ALsource *end;
ALsource **list = &Context->SourceList; ALsource **list = &Context->SourceList;
while(*list) while(*list)
list = &(*list)->next; list = &(*list)->next;
// Add additional sources to the list (Source->next points to the location for the next Source structure) // Add additional sources to the list (Source->next points to the location for the next Source structure)
end = *list;
while(i < n) while(i < n)
{ {
*list = calloc(1, sizeof(ALsource)); *list = calloc(1, sizeof(ALsource));
if(!(*list)) 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); alSetError(Context, AL_OUT_OF_MEMORY);
break; break;
} }