3 ms·
Problems: double free might still happen, except now some innocent memory block can be corrupted as well, which just happened to have the magic value in that ad
by vardump 7y ago
Problems: double free might still happen, except now some innocent memory block can be corrupted as well, which just happened to have the magic value in that address.
All memory allocations are now misaligned, decreasing performance. On some platforms misaligned access causes a bus error exception.
The marker would generally need to be at least 8 bytes. This would alleviate the problems, but also cause pretty significant overhead.
- saagarjha 7y agoI feel like the allocation header might already have a flags bit field where this might go.
- laughinghan 7y agoOn the other hand, the chances of an innocent memory block having a random 8-byte magic value is vanishingly small, so that would work even better. If free() took only 1ns to run and you called it 2^64 times, that would take >500 years.