Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting use after free() on windows. (dangling pointers)

I'm trying to detect "Use after free()" bugs, otherwise known as "Dangling pointers". I know Valgrind can be used to detect "Use after free" bugs on the *nix platform, but what about windows? What if I don't have the source? Is there a better program than Valgrind for detecting all dangling pointers in a program? A free and open source would be preferred , but I'll use a commercial solution if it will get the job done.

like image 850
rook Avatar asked Dec 06 '22 03:12

rook


2 Answers

The MSVC debug memory allocator already does this. When you get 0xfeeefeee from a pointer dereference you've dangled. With some luck that will bomb the program.

like image 179
Hans Passant Avatar answered Dec 29 '22 01:12

Hans Passant


You can use gflags.exe and the Debugging Tools for Windows to enable heap checking in a process:

  • http://msdn.microsoft.com/en-us/library/cc265885.aspx

It's been a while since I've used this, and I honestly can't remember how well it interacts with the C runtime heap as opposed to the Windows heap manager (to ensure that each malloc()/free()/new/delete call is separately checked).

Free, but not open source.

like image 29
Michael Burr Avatar answered Dec 29 '22 01:12

Michael Burr