Solved

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

Posted on 2004-04-28
12
326 Views
Last Modified: 2013-11-20
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
Comment
Question by:allmer
  • 7
  • 4
12 Comments
 
LVL 5

Author Comment

by:allmer
ID: 10943592
Also works if I start the debug version outside of VS.net.
0
 
LVL 12

Expert Comment

by:migel
ID: 10946756
Hi!
If you build id in release mode with DBG info will it crash?
0
 
LVL 5

Author Comment

by:allmer
ID: 10949707
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
 
LVL 12

Expert Comment

by:migel
ID: 10952152
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
 
LVL 5

Author Comment

by:allmer
ID: 10952838
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
 
LVL 5

Author Comment

by:allmer
ID: 10952912
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 5

Author Comment

by:allmer
ID: 10986893
Hi Miguel we are almost done here.
Please tell me how to get this release debugging to run.
Regards,
Jens
0
 
LVL 12

Expert Comment

by:migel
ID: 10993420
Hi!
Can you just run this build under debugger? Is debugger stoppped when crash occured?
0
 
LVL 5

Author Comment

by:allmer
ID: 10995764
Hi Migel,
no crash occurs while running in debugger.
That is the problem I have.
Thx
Jens
0
 
LVL 12

Expert Comment

by:migel
ID: 10996580
ok
when you run this program outside VS NET is it crash? Is system prompts you about debug crashed program?
0
 
LVL 5

Author Comment

by:allmer
ID: 10996807
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
 
LVL 14

Accepted Solution

by:
wayside earned 500 total points
ID: 11097991
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now