Is there Valgrind Memcheck like tool for windows to debug use after free errors? [closed]
As Lailin Chen pointed out in his answer to this question try one of these:
Dr. Memory: https://github.com/dynamorio/drmemory
UMDH: http://support.microsoft.com/kb/268343
AppVerifier: http://msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx
The method that worked for me was to write custom memory manager that provides global operators "new" and "delete", and lock every freed/usued memory block with VirtualProtect. This way any attempt to use freed memory will immediately trigger access violation which you can catch and debug. However, to be able to do this, you must "grab" all available memory (or 3/4 of it) using something like VirtualAlloc
and every memory block you return (from this initially allocated block) must be PAGE_SIZE
aligned (see GetSystemInfo
documentation), otherwise you won't be able to lock it reliably. Which means that even trivial application might require large amount of memory to use this method.
As for "valgrind alternative for windows" - I havent heard of it. Somebody somewhere posted that it might be possible to compile/use valgrind with cygwin, but I don't know if this is true or not.
Here's a valiant Valgring attempt, and I wish them the best:
http://sourceforge.net/p/valgrind4win/wiki/Home/
I am afraid, though, that in order to implement a proper "Valgrind for Windows", access to Windows source code is required.
IOW: When pigs fly.