Double free

Dynamically allocated storage, for example from new or malloc, must be freed only once.

Freeing the same data twice can corrupt the heap. This is a serious error.

ID

Observation

Description

1

Deallocation site

Second of two places where that storage was freed. This is where the error occurred.

2

Deallocation site

Places where the storage was freed earlier. Note that the pointer provided at the first deallocation may differ from that provided at the second deallocation. This can happen when pointers are assigned to one another.

Example

          
#include <stdlib.h>

int main(int argc, char **argv)
{
    char *p1, *p2;
    p1 = (char *)malloc(10); /* allocation site */
    p2 = p1;
    free (p1); /* deallocation site 1 */
    free (p2); /* deallocation site 2: error here */
}
        

Copyright © 2010, Intel Corporation. All rights reserved.