You might call me crazy after reading this post, but I would really request you to trust me when you read what I say here. In my attempt to understand situations where memory leak or other errors could be caused, I wrote the following code and tried compiling on my pc,
#include <iostream>
using namespace std;
class game
{
int x;
public :
char *s;
char read();
char manipulation();
};
char game :: read()
{
char string[100];
cout<<"Enter name ";
cin>>string;
s = string;
cout<<"Name is "<<&s<<endl;
}
int main()
{
game games,games1;
// games.read();
cout<<"Name is "<<games.s<<endl;
return 0;
}
If i execute games.read() in my main, my anti-virus software BITDEFENDER shows me the following error, “BITDEFENDER has detected an infected item in c:/c++/inline.exe. Virus name : Gen:Variant.Graftor.51542. The file was disinfected for your protection”
inline.cpp is the name of my program.
If i remove that line “games.read()”, it compiles fine. Is the pointer causing a memory leak somewhere?
Your anti-virus program just found a use-after-free vulnerability.
stringis a local array.You can’t use it after
read()exits.