tags:

views:

101

answers:

4
+2  Q: 

Pointer Validator

Hello, I am debugging a large project in C++. There are a few dereferenced pointers causing random crashes. Could you suggest me please best free tool for pointer validation? (Identification of use of invalid pointers)

(Otherwise it will took me ages to go through it manually)

Also I have used Memory Valuator program to get rid of the most memory leaks but it isn't very helpful with pointers being used after being invalidated. Platform is Windows.

UPDATE:

Before I post I have researched also other posts. And yes, it wasn’t helpful. So I would like to share my research.

One of the conditions was a FREE tool and I haven’t found any usable, and yes I have tested a dozen of them. Most of the suggested tools are designed for Leaked memory (which is not what I am looking for.) Most of pro tools like IBM’s purify do have a free or trial version but all of them are a waste of time (They only reports number of problem but nothing specific).
Other tools like Microsoft Application Verifier are pretty useful for memory or compatibility issues but it wasn’t able to identifying my problems.

Now I am testing commercial tools:

Memory Validator – perfect for mem leaks but feature “Detect deleted ‘this’ pointer” causes my application crash. (and I have spent ages with settings / config. )

Bug Validator – Much better. It identified some of the problems. However, it isn’t helpful very often. The whole Stack Trace is in crt/src/XString or Mutex initialization or inside some Critical Sections inside C++ libs. (That's it so far. I hope this info would be helpful.)

+8  A: 

For Unix, I recommend valgrind.

fschmitt
Specifically, memcheck tool with `--track-origins` :-)
Christoffer
+3  A: 

Read http://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows , since there's a good chance you're using Windows.

Reinderien
A: 

valgrind for Linux
(http://valgrind.org/)

Purify Plus for Windows
(http://www.ibm.com/software/awdtools/purifyplus/)

About the memory Leaks, how about writing your own little memory leak detector. (Hint: Very Easy to implement if you have single allocator & deallocator functions for dynamic memory)

Als
I have worked with Purify in past but it is quite expensive. And free version doesn't show any info - just number of detections so it is useless.
en667
A: 

Assuming VS2010, Run it under the debugger with the following setting:

Debug->Exceptions->Win32 Exceptions->"c0000005 Access Violation" (set the checkbox)

This would help you to get a first chance exception for pointer dereference issues such as the one in the code below

int main(){
    int buf[2];
    int *p = buf;

    p += 100;
    *p = 2;
}

It really helps as a first level technique! More advanced techniques would require WinDBG.

Chubsdad