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

**Code:** `double free or corruption` · **Category:** C/C++ · **Seen on:** C/C++

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/double-free-or-corruption)
