Re: stack corruption in release
r0d wrote:
Hi all,
i'm working on a big program, wich is an awful mix of C and C++. I'm
on windows XP, with Visual Studio 2008 SP1.
This program works fine in debug mode. But in release mode, there is a
crash without any message, and the catch() block don't catch nothing.
I located the function where the crash occurs. In this function, if i
add this code:
{
std::cout << " *** 1 *** " << std::endl;
vector<int> dum_vect( 520 );
std::cout << " *** 2 *** " << std::endl;
}
std::cout << " *** 3 *** " << std::endl;
the output is:
*** 1 ***
*** 2 ***
<crash>
That means that the crash occurs at the exit of the block, when the
vector is desalocated form the stack.
But why?
Coincidence.
And why there is no problem in debug, but only in release
mode?
Bad luck.
The title of this message is wrong. It's almost certainly not stack
corruption, but free store corruption. And the code that caused the
problem is somewhere else; it just happens to show symptoms here.
Look for deleting the same pointer twice, or writing beyond the end of
an allocated block. Those are the most common causes of free store
corruption, and the result can be a crash pretty much anywhere after
that when the code calls new or delete.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]