[openal] OpenAL realloc crash
roger
roger at egosoft.com
Fri Sep 9 05:57:02 EDT 2016
Hello,
Platform: Windows 10, msvc2015 update3, using OpenAL-Soft-1.17.2
We have a situation where we can end up with a crash in realloc, with
the error "Critical error detected c0000374".
In our specific case, we increased the number of sources up to 4096
(from the default 256) in the alsoft.conf like this:
[general]
sources = 4096
The number of voices remains at the (hardcoded) default 256, see ALc.c,
alcCreateContext, where it does this:
ALContext->MaxVoices = 256;
ALContext->Voices = *al_**calloc*(16, ALContext->MaxVoices *
sizeof(ALContext->Voices[0]));
Notice the memory is allocated using al_calloc, which does an al_malloc
with several #ifdef'ed implementations inside.
One of them does "manual alignment", another is using _aligned_malloc.
In our specific case _aligned_malloc is being used.
Now we can get into a situation where we actually need more voices,
which is handled in alSourcePlayv like this:
newcount = context->MaxVoices << 1;
if(newcount > 0)
temp = *realloc*(context->Voices, newcount *
sizeof(context->Voices[0]));
Notice it does a realloc - but that doesn't match with what al_malloc
did, e.g. :
- for HAVE__ALIGNED_MALLOC, it should do an _aligned_realloc(..., 16) //
where 16 is the alignment originally used when allocating ALContext->Voices
- for HAVE_ALIGNED_ALLOC, the pointer passed to realloc must have been
returned by an earlier call to malloc(), calloc() or realloc(), which
isn't the case since it's 'manually aligned'.
It probably needs something similar to al_free, where it uses the
0x55 and 0x0 markers to get back the original unaligned address, and
then manually align again on the realloc'ed address.
There are more places calling realloc. I assume it's quite likely they
can cause similar issues, but I haven't verified that.
It's probably a good idea to implement an al_realloc() function and call
that instead.
--
Best Regards
Roger Boerdijk
EGOSOFT GmbH, Heidestrasse 4, 52146 Würselen, Germany
Tel: +49 2405 4239970, www.egosoft.com
Geschäftsführer: Bernd Lehahn, Handelsregister Aachen HRB 13473
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://openal.org/pipermail/openal/attachments/20160909/98f5c8ab/attachment.html>
More information about the openal
mailing list