0

Memory access violation

Hi I have just now got a huge source code in terms no of files and no of code lines. I am getting an access violation error on pointer... Assume a pointer is of type myclass* p; So it is checked for null before using like below If(p) { p->dosomething(); } I could see during debug that pointer is corrupted but don't know where.. I feel that somewhere it got freed but not set to nullptr.. I tried to search for p getting deleted or assigned to some pointer but could not find any such statement in code base Can someone guide what to do now as issue is known but what is root cause is not figurable. Feel free to ask for queries. I will try to answer all of them but I won't be able to share code due to privacy concerns and issues. Thanks in advance...

15th Feb 2022, 4:03 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 odpowiedzi
+ 3
I've never worked with these tools myself, but you could run a valgrind memcheck to check for invalid memory operations. Other than that, set lots of breakpoints and grab lots of coffee. Sounds like a nasty bug.
15th Feb 2022, 4:45 PM
Schindlabua
Schindlabua - avatar
+ 1
Is there an array that is defined near the definition of p? Look for out-of-bounds array access that might overwrite the memory location for p.
15th Feb 2022, 6:05 PM
Brian
Brian - avatar
0
Good point.... Will check about your point in detail I was going through the code and observed that p is pointer of class ... There are 5 pointers including p defined in .h... All of them are class object pointers .... In short, Class myEngine { A* a; B* b; C* c; D* d; P* p; }; When constructor of myEngine is called , it initialise the first four with nullptr but not for p. When I checked for P class, it has only a parametric constructor and till the time I observe the issue due to p calling dosomething, constructor is not hit. Howcome it is not null till now ? Should I assign nullptr to p as well from class myEngine default constructor ? Any thoughts on this plz if possible 🙏
15th Feb 2022, 7:07 PM
Ketan Lalcheta
Ketan Lalcheta - avatar