[musl] Re: realloci(): A realloc() variant that works in-place
Andreas Schwab
schwab@linux-m68k.org
Fri Oct 31 18:35:10 GMT 2025
On Okt 31 2025, Thiago Macieira wrote:
> But I think any such thing would be extremely fragile. Very low-level library
> authors can probably get it right, but I wouldn't trust this feature to more
> than a few dozen people on the planet. We're talking about something like:
>
> void adjust_after_relocation(T *object, uintptr_t old) // or ptr_bits<T>
>
> The temptation is too great to cast the old to a T* and dereference it, which
> is UB because the memory has been freed, but will "happen to work" for
> sufficiently many executions that it might go unnoticed. Then there's the issue
> that the relocated T *object is itself in an inconsistent state and one must
> avoid calling most functions on it.
And it will not be thread safe. The freed memory can be allocated to
another thread any time.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
More information about the Libc-alpha
mailing list