title: Access violation in mlock
body: <p>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."</p>
  
  <p>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:</p>
  
  <pre><code>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()  
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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()  
  </code></pre>
  
  <p>and the another one</p>
  
  <pre><code>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++
  </code></pre>
  
  <p>I understand that there are some bugs in fpplication code, but question is have can I find it
  Question</p>