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.
double free or corruptionfree(): double free detected in tcache 2free(): invalid pointermalloc(): corrupted top sizemunmap_chunk(): invalid pointer 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
- Build with -fsanitize=address -g and run again
- Use std::unique_ptr/std::vector instead of raw new/delete
- Set pointers to nullptr after free
Detailed fix by platform
Shell
- cpp
g++ -g -fsanitize=address -fno-omit-frame-pointer main.cpp -o app && ./app valgrind --leak-check=full ./app
How to diagnose
- ASan — Report of first invalid free/write
- 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:
Similar errors
- 0xC0000005 The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation
- 0xC0000142 The application was unable to start correctly (0xc0000142)
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
Most viewed in C/C++
- undefined reference to main C/C++: undefined reference to `main' — (.text+0x20) in crt1.o
- was not declared in this scope C++: error: 'x' was not declared in this scope (undeclared identifier)
- control reaches end of non-void function C/C++: warning: control reaches end of non-void function [-Wreturn-type]
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 13 Oct 2026