Use-After-Free - Dangling Pointers
Understand use-after-free: accessing memory after it has been freed.
Use-After-Free
Use-after-free occurs when you access memory after calling free() on it.
Why It's Dangerous
- The memory may be reused by another allocation
- Reading or writing can corrupt data or crash the program
- Security vulnerabilities (exploitable by attackers)
How to Avoid
- Set pointers to
NULLafter freeing - Avoid keeping multiple pointers to the same block
- Use tools like MemC to visualize and catch these errors