[openal] OpenAL realloc crash
chris.kcat at gmail.com
Fri Sep 9 11:43:49 EDT 2016
On 09/09/2016 02:57 AM, roger wrote:
> 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:
> Notice it does a realloc - but that doesn't match with what al_malloc
Thanks for reporting this. This has already been fixed in the Git
version, along with most other uses of realloc (it's still used in a few
places, but they are using standard malloc/calloc/free as well).
> 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.
Unfortunately, there's no guarantee that a realloc function for aligned
memory will be available (C11 doesn't define one, and manual alignment
would be very tricky since it needs to know the size of the previous
allocation). The only way to safely do it is to allocate another block,
copy the contents, then free the old pointer. Which is a shame when it
could reuse the same address and just shrink (or grow, if enough head
space is there) the amount of memory used by it.
More information about the openal