0

I have a console application (written using MS VS2010 SP1). No MFC, no ATL, just standard library. In debug build everything works Ok. But in release build there is an access violation: "First-chance exception at 0x77b0206e in Mapp.exe: 0xC0000005: Access violation reading location 0x002cef58."

If I run app from MS VS (even release mode), everything works Ok and I can't find out what is going on. I've tried to use just-in-time debugging and I received call stack:

ntdll.dll!77b020cb()    
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
Mapp.exe!_unlock(int locknum=72090689)  Line 375    C
04320069()  

It happend when app is shutting down and object destruction proceeds: there is one line like 'delete ptr' which cause an exception. But I several times check that code and found nothing. I've tried to use CRT debug functions (memory leaks diagnostic, custom memory allocation hooks etc) and no results. Also I find out, that problem is solved when use the debug version of CRT (use Multi-threaded Debug (/MTd) in release configuration). One more thing: when I perform some minor changes to the code (e.g. write a line of debug code) a call stack is changing and every time it is totally different. for example:

ntdll.dll!77b0206e()    
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
Mapp.exe!_unlock_fhandle(int fh=72090689)  Line 491 C
04320069()  

and the another one

ntdll.dll!77b0206e()    
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
ntdll.dll!77b0201f()    
kernel32.dll!768cf1cc()     
Mapp.exe!free(void * pBlock=0x024950f0)  Line 51    C
Mapp.exe!CGISMapLineShape::~CGISMapLineShape()  Line 20 + 0x13 bytes    C++
Mapp.exe!CGISMapPolygonShape::`scalar deleting destructor'()  + 0x13 bytes  C++
Mapp.exe!CGISMapMultyPolygonShape::~CGISMapMultyPolygonShape()  Line 9  C++
Mapp.exe!CGISMapMultyPolygonShape::`scalar deleting destructor'()  + 0xc bytes  C++
Mapp.exe!CGISMapShapeCollection::Clear()  Line 307  C++

I understand that there are some bugs in fpplication code, but question is have can I find it Question

Roter
  • 1
  • 1
  • This is virtually impossible to solve without looking at the code. If I were you, I would begin with looking for uninitialised variables and double-deletes. – molbdnilo Aug 12 '11 at 15:00
  • Definitely a memory overwrite somewhere. You can carefully examine your code for a double delete, write past the end or beginning of allocated space or something like that. On linux you could also run your program through valgrind, i'm not sure what the windows alternatives are. – Torp Aug 12 '11 at 15:12

2 Answers2

1

In release builds the memory handling is much different from debug builds. This error normally happen when you try to access an already deleted object. The callstack is crap if you don't load the symbols.

Pascal
  • 2,197
  • 3
  • 24
  • 34
0

Finnaly I've cought it! It was several bugs and all of them - index out of range in array manipulation.

Thanks all for help!

Roter
  • 1
  • 1