Fix source and buffer out-of-memory conditions

This commit is contained in:
Chris Robinson 2008-01-15 16:30:43 -08:00
parent a6213ebfc7
commit a11f25e47b
2 changed files with 24 additions and 24 deletions

View File

@ -95,8 +95,13 @@ ALAPI ALvoid ALAPIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers)
while(i < n) while(i < n)
{ {
*list = calloc(1, sizeof(ALbuffer)); *list = calloc(1, sizeof(ALbuffer));
if(*list) if(!(*list))
{ {
alDeleteBuffers(i, puiBuffers);
alSetError(AL_OUT_OF_MEMORY);
break;
}
puiBuffers[i] = (ALuint)ALTHUNK_ADDENTRY(*list); puiBuffers[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
(*list)->state = UNUSED; (*list)->state = UNUSED;
g_uiBufferCount++; g_uiBufferCount++;
@ -105,11 +110,6 @@ ALAPI ALvoid ALAPIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers)
list = &(*list)->next; list = &(*list)->next;
} }
} }
// If we didn't create all the Buffers, we must have run out of memory
if (i != n)
alSetError(AL_OUT_OF_MEMORY);
}
else else
{ {
// Pointer does not point to enough memory to write Buffer names // Pointer does not point to enough memory to write Buffer names

View File

@ -65,9 +65,14 @@ ALAPI ALvoid ALAPIENTRY alGenSources(ALsizei n,ALuint *sources)
while(i < n) while(i < n)
{ {
*list = calloc(1, sizeof(ALsource)); *list = calloc(1, sizeof(ALsource));
if(*list) if(!(*list))
{ {
sources[i]=(ALuint)ALTHUNK_ADDENTRY(*list); alDeleteSources(i, sources);
alSetError(AL_OUT_OF_MEMORY);
break;
}
sources[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
(*list)->source = sources[i]; (*list)->source = sources[i];
InitSourceParams(*list); InitSourceParams(*list);
@ -77,11 +82,6 @@ ALAPI ALvoid ALAPIENTRY alGenSources(ALsizei n,ALuint *sources)
list = &(*list)->next; list = &(*list)->next;
} }
} }
// If we didn't create all the Sources, we must have run out or memory
if(i != n)
alSetError(AL_OUT_OF_MEMORY);
}
else else
{ {
// Not enough resources to create the Sources // Not enough resources to create the Sources