Skip to content

Glossary

Double free

Freeing the same heap allocation twice, which corrupts allocator free lists and can lead to memory corruption (CWE-415).

A double free (CWE-415) happens when a program passes the same pointer to free (or delete) more than once. The allocator then records the same chunk in its free lists twice, so two later allocations can receive overlapping memory. The typical cause is an error path and a cleanup path that both believe they own the object.

Modern glibc detects many cases and aborts with free(): double free detected in tcache 2. AddressSanitizer reports every occurrence with both free stacks. Fix it with a single cleanup point and by setting the pointer to NULL after freeing it. See heap corruption and use-after-free.