Reputation: 55
Currently I am using Valgrind to check memory leak and take Purify as an alternative. Valgrind can find out the access violation on an array created in heap but not in stack.
char* a = static_cast<char*>(malloc(sizeof(char) * 5));
a[7] = 'c';
printf("%c\n", a[7]);
free(a);
Valgrind points of invalid write and read in the above code, but not the following code.
char a[5] = {0};
a[7] = 'c';
printf("%c\n", a[7]);
Can Purify identify the access violation of the both blocks of code?
Upvotes: 0
Views: 121
Reputation: 534
According to the user's guide (ftp://ftp.software.ibm.com/software/rational/docs/v2003/purify/html/ht_m_sbr.htm) and (ftp://ftp.software.ibm.com/software/rational/docs/v2003/purify/html/ht_m_sbw.htm), Purify can detect both stack boundary read and write.
However, trying your actual examples only the violation on heap data was detected also by Purify. I have only tested the latest version from IBM (7.0.1), both for Linux and Solaris.
You may want to look at -fsanitize=address for gcc 4.8 and later.
Upvotes: 0