tags:

views:

202

answers:

3

FILE * __cdecl _getstream

I'm calling an fopen and it keeps crashing.

AfxMessageBox("getting here 1");
FILE * filePtr = fopen(fileName, ("rb") );
AfxMessageBox("getting here 2");

For some reason I never get to the second messagebox. What makes it more interesting is that in debug mode the app works perfectly.. Most frustrating..

A: 

I guess that something is wrong with fileName (does it have trailing zero ?)

Try to comment fopen line out and see what will happen.

Dmitry Khalatov
A: 

I would suspect there's nothing wrong with that part of your program. The most likely scenario is that you've got some kind of memory corruption earlier in the code, and that just happens to be where it shows up.

Have you tried running it through the rest of the program (after that part) in debug mode? If it is some kind of memory corruption, the debug-mode allocator should catch it when it goes to deallocate the corrupted areas of memory, if not sooner. Assuming you're using a compiler with a thorough debugging memory allocator, of course.

Head Geek
The problem is the issue doesn't happen in debug mode. And it also only happens for some files, not all. I think you're right. I guess I'm going to go look at the memory allocation for the whole process. Not easy in release mode.
baash05
+1  A: 

I think memory corruption. On Windows (which the __cdecl makes me think you are using), there is the gflags utility which comes with the Windows Debugging Tools. With it, you can make each heap allocation have it's own page -- this will help catch memory overruns and double freeing immediately at the point of the problem.

I wrote up instructions on my blog:

http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/02/06/6-_2200_Pointers_2200_-on-Debugging-Unmanaged-Code.aspx

There are other tips for finding this kind of bug there too.

Lou Franco