[musl] Re: realloci(): A realloc() variant that works in-place

Thiago Macieira thiago@macieira.org
Fri Oct 31 19:17:30 GMT 2025


On Friday, 31 October 2025 11:35:10 Pacific Daylight Time Andreas Schwab wrote:
> > 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.

No argument there. It's already UB. What I meant is that it will "happen to 
work" under quite a lot of software testing for the problem to go unnoticed, 
and then present itself as a heisenbug to the downstream user.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 870 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251031/15e2abf5/attachment.sig>


More information about the Libc-alpha mailing list