Heap damage not detected by Valgrind or Electric Fence. Should I be suspicious? (C ++)

I recently ran into my first battle (resolved) with heap damage. On my linux machine at home, the culprit code exits without errors using valgrind and an electric fence (with gdb). However, on a Windows machine in our laboratory, I consistently receive an error message related to the heap corruption from VS described in my link.

No wonder (or at least unusual) that valgrind and electric fence will not detect such a problem? Someone else mentioned, perhaps, a similar error that eluded valgrind in the answer here . What could be some reasons why this problem would not be detected by these tools? Is there any reason to doubt that the mistake is actually a bunch of corruption?

Update . As mentioned in the article describing the original problem, I found that the problem is due to the presence of pointers to elements in std :: vector, which became bad. Replacing vectors with std :: list (to which pointers do not become invalid when adding new elements) eliminates the problem. Therefore, returning to my question about why valgrind did not detect the problem, I ask if there are any recommendations on how to avoid a similar situation in the future, namely the memory problem that valgrind is not detected, which is one of my favorites tools. Obviously, better understanding how STL works would be a good idea. Perhaps I need to be more assertive with a statement in my programming, etc.

+5
source share
3 answers

Thus, the obvious reason Valgrind was not able to detect your heap damage is because corruption did not occur at all with the implementation of the GCC STL (i.e. no errors were detected).

Unfortunately, Valgrind operates at a much lower level than STL, and so many errors remain undetected. For instance:

std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.resize(0);
v[1] = 42;  // Oops. Out of bounds access, but Valgrind is silent

Fortunately, the GCC STL has a special debugging mode designed for many problems. Try creating source code with -D_GLIBCXX_DEBUG. He will probably catch the original problem and can catch more problems that you still don't know about.

+4
source

, , . memtest86 , .

, , (, ), Windows - , .

0

, . , .

, Parallel Studio, ​​Parallel Studio, .

0
source

All Articles