diff options
author | Chris Robinson <[email protected]> | 2015-09-21 13:47:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2015-09-21 13:51:56 -0700 |
commit | 07d0bddb4f74090e1fb2157dae0ef4e59f8f2fee (patch) | |
tree | 3add1be57dedfb33040dcf212e700883d6f2f2a2 | |
parent | 33ac3095dd67cdd02c06291e96aca1b061fcc7cf (diff) |
Avoid a potential race condition with NewThunkEntry
It's possible for another invocation to increase the array size in between the
ReadUnlock and WriteLock calls, causing the 'i' index to refer to a taken
entry.
-rw-r--r-- | OpenAL32/alThunk.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/OpenAL32/alThunk.c b/OpenAL32/alThunk.c index ed0aa83c..0cebad42 100644 --- a/OpenAL32/alThunk.c +++ b/OpenAL32/alThunk.c @@ -62,6 +62,19 @@ ALenum NewThunkEntry(ALuint *index) ReadUnlock(&ThunkLock); WriteLock(&ThunkLock); + /* Double-check that there's still no free entries, in case another + * invocation just came through and increased the size of the array. + */ + for(;i < ThunkArraySize;i++) + { + if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE) == AL_FALSE) + { + WriteUnlock(&ThunkLock); + *index = i+1; + return AL_NO_ERROR; + } + } + NewList = al_calloc(16, ThunkArraySize*2 * sizeof(*ThunkArray)); if(!NewList) { |