double free or corruption C/C++ Origin: Application & API Last updated 13 Oct 2026

C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)

Memory was freed twice or the heap was corrupted (buffer overflow, freeing a non-heap pointer), so glibc aborted the program.

Exact message you may see double free or corruptionfree(): double free detected in tcache 2free(): invalid pointermalloc(): corrupted top sizemunmap_chunk(): invalid pointer
Seen on: C/C++

Meaning

Common sources: two owners freeing the same pointer, copying a class with a raw pointer member (shallow copy then two destructors), writing past an array’s end, or delete on stack memory. AddressSanitizer pinpoints it.

Common causes

  • Same pointer freed/deleted twice
  • Shallow copy of a class owning raw memory (rule of three)
  • Buffer overflow corrupting heap metadata
  • Freeing memory not from malloc/new

⚡ Quick fix

  1. Build with -fsanitize=address -g and run again
  2. Use std::unique_ptr/std::vector instead of raw new/delete
  3. Set pointers to nullptr after free

Detailed fix by platform

Shell

  1. cpp
    g++ -g -fsanitize=address -fno-omit-frame-pointer main.cpp -o app && ./app
    valgrind --leak-check=full ./app

How to diagnose

  1. ASan — Report of first invalid free/write
  2. Ownership — Who frees the memory?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0xC0000005 — The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation (Windows)0xC00000050xC0000142 — The application was unable to start correctly (0xc0000142) (Windows)0xC0000142AddressSanitizer: heap-buffer-overflow — C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N (C/C++)AddressSanitizer: hea…AddressSanitizer: heap-use-after-free — C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free (C/C++)AddressSanitizer: hea…attempted to access privacy-sensitive data without a usage description — This app has crashed because it attempted to access privacy-sensitive data without a usage description (iOS)attempted to access p…Bus error — C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file (C/C++)Bus errorCannot allocate memory — fork: Cannot allocate memory / ENOMEM (Linux)Cannot allocate memoryCould not cast value of type — Swift: Could not cast value of type 'X' to 'Y' (iOS)Could not cast value …double fr…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.