4

Is there any tool to help me detect heap corruption in C++? I can't provide source code because it's a big project. I can use any tool that works with Visual Studio or with xcode. The tool should work fine with multithreading. The problem is not very common, it appears after a long time and only in very special cases(they were not detected precisely!).

Thank you!

EDIT:

Thanks you all for your answers! I will test the tools and I will accept one answer after the tests.

Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211
  • 1
    Under which conditions do you want to detect this heap corruption? Can you run the process under a debugger? Debug or release build? Developer or production machine? – Martin Ba Jan 14 '11 at 08:51
  • I can run the process in debug mode, I have the source code, I can run it on PC/MAC/iPhone/iPad(99% of the code, some small initialization part is different and some OS specific parts, but the problem is in all builds, so it must be from common parts) – Mircea Ispas Jan 14 '11 at 09:05

4 Answers4

8

Valgrind is the defacto tool for doing memory instrumentation for native code. It, however, does not run on Windows (OS X is fine).

There are a few commercial tools which do run on Windows, and while they feature a GUI, are in my opinion inferior to Valgrind.

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
5

The debugging tools for Windows include gflags and page heap which help detecting heap corruptions.

John
  • 5,561
  • 1
  • 23
  • 39
2

On Mac OS X (which I presume is what you mean when you say Xcode), you have a whole bunch of memory debugging tools already, e.g. http://developer.apple.com/library/mac/#releasenotes/DeveloperTools/RN-MallocOptions/index.html which lets you turn on heap checking via environment variables.

Paul R
  • 208,748
  • 37
  • 389
  • 560
1

On Windows use Application Verifier

Kirill Kovalenko
  • 2,121
  • 16
  • 18