简体   繁体   中英

how to check memory corruption in C++

I have an issue in my project. Sometimes execution fails with the error "unabe to access a reading/writing location xxxxx". I know it is a memory corruption error. But how can I trace that error. It is failing at memory deallocation of a variable , if I comment that line it is processing fine. That is , the the memory for this variable has got released already. Earlier it was working fine, I added code recently but i didnt change anything related to this. How can I check the memory corruption fo this.

Use valgrind if you're under linux, it will show you exactly what's happening if you stomp your memory.

On windows: see here .

With the information given, you'll have to step through all your code that you have added recently (if this is a recent issue) and evaluate and check each line and see if you are stomping memory. memcopy is a command that can cause this type of error if you're allocating to much for the size of the item you are copying.

Make sure you are only deleting your objects(pointers) once as well.

If you are using windows, try winDbg. Its the best and very powerful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM