CMD Simulator

Double-Free - Invalid free()

Learn why calling free() twice on the same pointer is undefined behavior.

Double-Free

Double-free is calling free() on the same pointer more than once.

Why It's Bad

  • Undefined behavior: the program may crash or corrupt the heap
  • Can lead to security vulnerabilities
  • The allocator's internal structures can be corrupted

How to Avoid

  • Free each block exactly once
  • Set the pointer to NULL after freeing
  • MemC detects and reports double-free at runtime