Definition

MITRE’s description of CWE-416: The product reuses or references memory after it has been freed. At some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. Any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer.

Common consequences MITRE lists

  • Integrity: Modify Memory
  • Availability: DoS: Crash, Exit, or Restart
  • Confidentiality: Read Memory
  • Integrity, Confidentiality, Availability: Execute Unauthorized Code or Commands

Why it matters

Once freed memory is reused, the stale pointer reads or writes whatever now lives there; attackers shape that memory to leak data or take control of execution.

How to prevent it

  • Prefer memory-safe languages, or ownership types such as std::unique_ptr in C++, so that object lifetimes are enforced.
  • Clear pointers after freeing them and do not keep raw pointers across callbacks, threads or asynchronous work.
  • Test with AddressSanitizer and fuzzing, and use a hardened allocator where the platform offers one.

Guides on this site

Practice

References

  1. CWE-416 in the MITRE CWE list (version 4.20)
  2. 2025 CWE Top 25 Most Dangerous Software Weaknesses (MITRE CWE Program)

List data from MITRE; the name, definition and consequences are from MITRE’s CWE 4.20 catalogue. A guide is listed as the main subject when the weakness is what the guide is about, and as covering it when a dedicated section or worked example addresses it.

CWE content: Copyright © 2006–2026, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation. CWE™ is free to use by any organization or individual for any research, development, and/or commercial purposes, per these CWE Terms of Use. Accordingly, The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. Any copy you make for such purposes is authorized on the condition that you reproduce MITRE’s copyright designation and this license in any such copy. CWE is a trademark of The MITRE Corporation. CWE Terms of Use.