Contents

Deallocation of deallocated memory

Detects attempts to free deallocated memory.

Overview

Use this check to detect when you call free on deallocated memory, commonly referred to as a double free error. Attempting to deallocate memory more than once can result in a crash or other unpredictable behavior. Available in Xcode 7 and later.

Deallocation of freed memory in C

In the following example, the code deallocates the p_int variable after the call to free its memory:

int *pointer = malloc(sizeof(int));
free(pointer);
free(pointer); // Error: free called twice with the same memory address 

Solution

Ensure that you call the free function just once for memory you allocate.

See Also

Address Sanitizer