Static Analysis Problem Type Reference
Use of pointer to deallocated storage.
This diagnostic covers various ways a pointer value can be used after the storage to which it points has been deallocated. There is another diagnostic type for the specific error of dereferencing a pointer after it has been freed. This diagnostic covers other uses, such as returning the address of deallocated storage from a function.
|
ID |
Code Location |
Description |
|---|---|---|
|
1 |
Bad memory access |
The place where the bad address was used |
|
1 |
Deallocation site |
The place where the address was deallocated |
#include <iostream>
using namespace std;
int glob;
int *UseDeallocatedStorage()
{
int *p = new int[10];
delete [] p; // p is now a stale pointer
if (p != 0) // used in compare
cout << "p == 0: " << p << endl; // used in print
glob = (int) p; // used in type conversion to integer
}
return (p); // used as function return
}
int main(int argc, char **argv)
{
(void)UseDeallocatedStorage();
return 0;
}