Access in freed memory
Go Up to Access Errors
An Access In Freed Memory error occurs when memory is accessed after it has been freed. Typically, the memory has been allocated with new
or malloc
and deallocated with delete
or free
. The following code shows an example:
#include<tchar.h>
#include<stdio.h>
#include<dir.h>
class someclass{
int fnumber;
public:
int getnumber(){return fnumber;}
void setnumber(int nw){fnumber = nw;}
int doublev(int val){return val*2;}
int publicalval;
};
void myf()
{
someclass *myc = new someclass();
delete myc;
myc->publicalval = 10; // error
}
int _tmain(int argc, _TCHAR* argv[])
{
myf();
return 0;
}