From: Luke D. <cod...@ho...> - 2007-01-31 11:23:24
|
----- Original Message ----- From: "kmittal" <kmi...@gm...> To: <min...@li...> Sent: Wednesday, January 31, 2007 2:02 AM Subject: [Mingw-users] Strange Crash with MinGW and STLport > > Hi, > > I am compiling a program with MinGW (3.4.2), using STLPort libraries > (5.1.0). The program deals with strings and streams, and as far as my > understanding goes, GCC 3.4 , STLPOrt and strings dont really go very > well. > > Anyways, I am experiencing some of the strangest crash I have ever seen > upon > running my executable. Unfrotunatley the files are too big to list here, > so > I will try and explain in simple terms. > > My header files declares lots of variables, all of different sorts, but > mostly of type unsigned char *. Now, when I run my program after > compiling, > the program seems to crash. Using GDB, I narrow it down to a crash on the > destructor, where a particular variable is delted (by calling delete[] ). > I > have made sure that the variable is checked for NULL before calling delete > on it. Besides, the variable also has a valid value in it when checked > through GDB. > > Also, I get a warning about invalid address being passed to RTlheap. > > Now, to stop the crash, all I do is put the declaration of the variable to > a > different line number, and that does the job. So, in context, if I declare > > unsigned char * a; > unsigned char *b; > > The program crashes. But If i Do > > unsigned char * b; > unsigned chat * a; > > The program runs fine. > > Another strange anomaly here is that if I DO want to keep the order of the > variables same and not get the program to crash, all I need to do is > declare > a dummy vraible, of any type (int, char etc..), adn then it seems to work > ok. I dont even need to use the variable, or initialise it. This sort of behaviour is not unusual. Typically you have a bug that causes part of the stack to be corrupted, and changing your variable declarations can change the placement of objects on the stack so that the crash can be accidentally avoided or hidden. Have you tried using GDB to step through your code? Unfortunately I doubt anyone will be able to help unless you post a complete program that demonstrates the crash. Luke > > Since this is a porting effort, I am not at much liberty to change headers > unless necessary, and just wonderign if anyone has an idea about this? My > guess is either the stack is getting messed up, or the variable is not > being > initialised, but then again, why would it work when it is re-ordered at > the > top? > > Another thing I noted when debugging with GDB was that the program crashes > on a incremenring a vector i.e. > > std::vector<char*>::iterator aPos; > char *aPtr; > aPos = cleanupStack.begin(); > while( aPos != cleanupStack.end() ) > { > aPtr = *aPos; > delete [] aPtr; > aPos++; > } > > The crash happens at aPos++. > > The STLPort library has been built with the install-dbg-static option, and > is statically linked against the application > > Thanks in advance. |