title: free.c throws exception with "this program has stopped working"
body: <p>When I run the program (server.exe) with Visual C++ 2010 Express's debugger, it runs perfectly, but when I run it as an exe it does not; it crashes with a "Server.exe has stopped working" dialog.</p>
  
  <p>Next I renamed the exe to "ServerInstaller.exe" and it worked, so I figured it is a permissions error, BUT it does not work with "Server.exe" in adminstrator mode.</p>
  
  <p>I then attached the debugger in VC++ to the "Server.exe" program, and it came up with an exception in "free.c".</p>
  
  <p>The code in this file is</p>
  
  <pre><code>void __cdecl _free_base (void * pBlock)
  {
  
          int retval = 0;
  
  
          if (pBlock == NULL)
              return;
  
          RTCCALLBACK(_RTC_Free_hook, (pBlock, 0));
  
          retval = HeapFree(_crtheap, 0, pBlock);   // Exception thrown in this function
         if (retval == 0)
          {
              errno = _get_errno_from_oserr(GetLastError());
          }
  }
  </code></pre>
  
  <p>The exception is </p>
  
  <blockquote>
    <p>Unhandled exception at 0x770ae3be in Server.exe: 0xC0000005: Access
    violation reading location 0x3765f8c7.</p>
  </blockquote>
  
  <p>I checked up the value for pBlock and it is 0x007f82c0.</p>
  
  <p>My Program.</p>
  
  <p>My program is a RakNet server, and a player has just been deleted successfully.
  The server is checking for messages from RakNet at that point</p>
  
  <p>Stack Trace back</p>
  
  <pre><code>    ntdll.dll!770ae3be()    
      [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
      ntdll.dll!770ae023()    
      kernel32.dll!75e814dd()     
  &gt;   msvcr100d.dll!_free_base(void * pBlock)  Line 50 + 0x13 bytes   C
      msvcr100d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse)  Line 1431 + 0x9 bytes  C++
      msvcr100d.dll!_free_dbg(void * pUserData, int nBlockUse)  Line 1265 + 0xd bytes C++
      msvcr100d.dll!free(void * pUserData)  Line 49 + 0xb bytes   C++
      RakNetDebug.dll!RakNet::_RakFree_Ex(void * p, const char * file, unsigned int line)  Line 165 + 0xc bytes   C++
      RakNetDebug.dll!RakNet::ReliabilityLayer::FreeInternalPacketData(RakNet::InternalPacket * internalPacket, const char * file, unsigned int line)  Line 3766 + 0x17 bytes C++
      RakNetDebug.dll!RakNet::ReliabilityLayer::RemovePacketFromResendListAndDeleteOlderReliableSequenced(RakNet::uint24_t messageNumber, unsigned __int64 time, DataStructures::List&lt;RakNet::PluginInterface2 *&gt; &amp; messageHandlerList, const RakNet::SystemAddress &amp; systemAddress)  Line 2391   C++
      RakNetDebug.dll!RakNet::ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer(const char * buffer, unsigned int length, RakNet::SystemAddress &amp; systemAddress, DataStructures::List&lt;RakNet::PluginInterface2 *&gt; &amp; messageHandlerList, int MTUSize, unsigned int s, RakNet::RakNetRandom * rnr, unsigned short remotePortRakNetWasStartedOn_PS3, unsigned int extraSocketOptions, unsigned __int64 timeRead, RakNet::BitStream &amp; updateBitStream)  Line 776   C++
      RakNetDebug.dll!RakNet::ProcessNetworkPacket(RakNet::SystemAddress systemAddress, const char * data, const int length, RakNet::RakPeer * rakPeer, RakNet::RakNetSmartPtr&lt;RakNet::RakNetSocket&gt; rakNetSocket, unsigned __int64 timeRead, RakNet::BitStream &amp; updateBitStream)  Line 5012 C++
      RakNetDebug.dll!RakNet::RakPeer::RunUpdateCycle(unsigned __int64 timeNS, unsigned __int64 timeMS, RakNet::BitStream &amp; updateBitStream)  Line 5099 + 0x81 bytes  C++
      RakNetDebug.dll!RakNet::UpdateNetworkLoop(void * arguments)  Line 5868  C++
      msvcr100d.dll!_callthreadstartex()  Line 314 + 0xf bytes    C
      msvcr100d.dll!_threadstartex(void * ptd)  Line 297  C
      kernel32.dll!75e833aa()     
      ntdll.dll!770b9ef2()    
      ntdll.dll!770b9ec5() 
  </code></pre>