Tools for finding memory corruption in managed c++ code?
-
09-06-2019 - |
Question
I have a .NET application, which is using an open source C++ compression library for compressing images. We are accessing the C++ library via managed C++. I'm seeing heap corruption during compression. A call to _CrtIsValidHeapPointer is finding an error on a call to free() when cleaning up after compression.
My question is, are there tools such as Purify to help diagnosis this problem and what is causing the heap corruption when working in a combination of managed and unmanaged code? I do have the exception caught in the debugger, but it would be nice to have other tools to help find the solution to the problem.
Solution
In native code, if the corruption always occurs in the same place in memory, you can use a data breakpoint to break the debugger when that memory is changed. Unfortunately, you cannot set a data breakpoint in the managed C++ environment, presumably because the GC could move the object in memory.
Not sure if this helps, but hopefully it leads you off in the right direction.
OTHER TIPS
on *nix, there's a tool called valgrind that I use for dealing with memory issues, like memory leaks and memory corruption.
Rational Purify for Windows supports .NET, so I guess that could be used?