• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Some strange corruption. Works in debug and in release mode within VS.net. Does not run outside of VS.net.

Hi experts,
I wrote a little programm which extracts some data from an .rtf file.
It works in debug mode and it also works in release mode when excecuted from within VS.net.
It crashes, however, if I let it run outside of VS.net.

You can download the project as a zip file here:
http://hippler.bio.upenn.edu/source.zip. All the source files are in there.
The error I get is something with strchr but I think I corrupted the heap somewhere.
An example file to process is also included.

I would need some advise on how to prevent things like this from happening in the future.

Please have a look,
Jens
0
allmer
Asked:
allmer
  • 7
  • 4
1 Solution
 
allmerAuthor Commented:
Also works if I start the debug version outside of VS.net.
0
 
migelCommented:
Hi!
If you build id in release mode with DBG info will it crash?
0
 
allmerAuthor Commented:
Hi migel,
I am not sure I am following you here.
If I build a release version and run it it will eventually crush at one point or another.
What is DBG info?
Regards,
Jens
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
migelCommented:
Hi!
To add debug info into the release build you have to create new project configuration:
1.Choose Build|Configuration manager
select <New...> in the "Active solution configuration" combo
type Release DBG in the Solution configuration Name edit
choose Release in the Copy Settings from combo
in the project options choose
Release DBG in the configuration combo
select Programm database int the Configuration Properties|C/C++|General-Debug information  format
select Yes int the Configuration Properties|Linker|Debugging-Generate Debug Info
After tha your program release build will have debug info so debugger can show your crash point in the source code/
Now if your programm crash Windows will attach Just in time debugger so you can watch what happens
0
 
allmerAuthor Commented:
I did what you told me above but I think I missed something because now I get two unresolved symbols:

QueryCreator error LNK2019: unresolved external symbol __beginthreadex referenced in function "public: int __thiscall CWinThread::CreateThread(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES *)" (?CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTRIBUTES@@@Z)

QueryCreator error LNK2019: unresolved external symbol __endthreadex referenced in function "void __stdcall AfxEndThread(unsigned int,int)" (?AfxEndThread@@YGXIH@Z)


So the programm won't compile.
I looked through the former questions and I could get rid of a third unresolved symbol but these to persist.
Jens.
0
 
allmerAuthor Commented:
I am also having another problem, which could be involved in this specific point:
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20968235.html
If I do what you set above, the
#include "stdafx.h" has to be changed to the following: //#include "../querycreator/stdafx.h"
since the files queries.cpp and query.cpp are located in a directory called shared whereas
the application is in the folder querycreator.
Cheers,
Jens
0
 
allmerAuthor Commented:
Hi Miguel we are almost done here.
Please tell me how to get this release debugging to run.
Regards,
Jens
0
 
migelCommented:
Hi!
Can you just run this build under debugger? Is debugger stoppped when crash occured?
0
 
allmerAuthor Commented:
Hi Migel,
no crash occurs while running in debugger.
That is the problem I have.
Thx
Jens
0
 
migelCommented:
ok
when you run this program outside VS NET is it crash? Is system prompts you about debug crashed program?
0
 
allmerAuthor Commented:
It just crashes and wants to send information to Microsoft about it.
No debugging possible at that point.
But that is not important anymore because I rewrote the whole thing and it is running, now.
I would like your Release DBG to get running ;-)
If that works I can hopefully spot all the problems .. at least most of them after release.
Regards Jens
0
 
waysideCommented:
I have found your bug.

The problem is with your  CQuery::CQuery(CQuery &rValue) constructor and your Query &CQuery::operator=(CQuery &rValue) operator overload.

The original code (which is virtually identical for both) looks like this:

CQuery::CQuery(CQuery &rValue) {
  if(rValue.dtaFileName != NULL) {
    dtaFileName = new char[strlen(rValue.dtaFileName)+1];
    strcpy(dtaFileName,rValue.dtaFileName);
  } else
    dtaFileName = NULL;
  initialized = rValue.initialized;
  mass = rValue.mass;
  if(sequence != NULL) {  //  <===!!! PROBLEM IS HERE !!!===>
    sequence = new char[strlen(rValue.sequence)+1];
    strcpy(sequence,rValue.sequence);
  } else
    sequence = NULL;

The line marked above needs to be

  if(rValue.sequence != NULL) {

The problem is that you are testing the value of the new, uninitialized object, *not* the one you are copying from.

In debug this will work all the time because the memory is initialized to 0xcdcdcdcd for you, so the test always passes and you allocate memory.

In release mode, it works most of the time, because the random chunk of memory you get for the new object will have a non-null value, and memory will be allocated.

Every once in a while, though, the value will be NULL, so you don't allocate the memory, and it crashes further down the road.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now