Memory is accessed after it has been deallocated.
This is a serious error because the storage being accessed could have been reused. Therefore, a read could deliver an unpredictable value and a write could corrupt another variable or the entire heap. This condition is also called a "stale pointer" error, indicating that a pointer has been used after it has become invalid or stale.
ID |
Observation |
Description |
---|---|---|
1 |
Bad memory access |
The place the memory was accessed |
#include <stdio.h> int main(int argc, char **argv) { int *p, *q; p = (int *)malloc(4); *p = 1; free(p); q = (int *)malloc(4); *q = 2; *p = 3; // error here: can't use p after it was freed printf("*q = %d\n", *q); // Will this print "q = 2" or "q = 3"? }
Copyright © 2010, Intel Corporation. All rights reserved.