【问题标题】:free.c throws exception with "this program has stopped working"free.c 抛出“这个程序已经停止工作”的异常
【发布时间】:2012-10-11 13:22:41
【问题描述】:

当我使用 Visual C++ 2010 Express 的调试器运行程序 (server.exe) 时,它运行良好,但当我将它作为 exe 运行时,它却没有;它会因“Server.exe 已停止工作”对话框而崩溃。

接下来我将 exe 重命名为“ServerInstaller.exe”并且它可以工作,所以我认为这是一个权限错误,但它不适用于管理员模式下的“Server.exe”。

然后我将 VC++ 中的调试器附加到“Server.exe”程序,它在“free.c”中出现异常。

这个文件中的代码是

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());
        }
}

例外是

Server.exe 中 0x770ae3be 处未处理的异常:0xC0000005:访问 违规读取位置0x3765f8c7。

我检查了 pBlock 的值,它是 0x007f82c0。

我的程序。

我的程序是一个 RakNet 服务器,一个播放器刚刚被成功删除。 此时服务器正在检查来自 RakNet 的消息

堆栈回溯

    ntdll.dll!770ae3be()    
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
    ntdll.dll!770ae023()    
    kernel32.dll!75e814dd()     
>   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<RakNet::PluginInterface2 *> & messageHandlerList, const RakNet::SystemAddress & systemAddress)  Line 2391   C++
    RakNetDebug.dll!RakNet::ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer(const char * buffer, unsigned int length, RakNet::SystemAddress & systemAddress, DataStructures::List<RakNet::PluginInterface2 *> & messageHandlerList, int MTUSize, unsigned int s, RakNet::RakNetRandom * rnr, unsigned short remotePortRakNetWasStartedOn_PS3, unsigned int extraSocketOptions, unsigned __int64 timeRead, RakNet::BitStream & updateBitStream)  Line 776   C++
    RakNetDebug.dll!RakNet::ProcessNetworkPacket(RakNet::SystemAddress systemAddress, const char * data, const int length, RakNet::RakPeer * rakPeer, RakNet::RakNetSmartPtr<RakNet::RakNetSocket> rakNetSocket, unsigned __int64 timeRead, RakNet::BitStream & updateBitStream)  Line 5012 C++
    RakNetDebug.dll!RakNet::RakPeer::RunUpdateCycle(unsigned __int64 timeNS, unsigned __int64 timeMS, RakNet::BitStream & 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() 

【问题讨论】:

  • 您的程序正在破坏堆。这种损害从来没有在它失败的时候造成,它是在更早的时候造成的。永远不要假设崩溃的代码与错误有关,首先假设它是您自己的代码。

标签: c++ visual-c++ stack visual-c++-2010-express


【解决方案1】:

重建项目可能会对您有所帮助。它对我有用

【讨论】:

    【解决方案2】:

    我遇到了这个问题,不是多次删除,而是编译上的问题(使用VisualStudio2012) 我重新编译程序,问题解决了

    【讨论】:

      【解决方案3】:

      如果你的指针有一个值,并且你得到这样的错误,这很可能意味着你试图多次释放内存。检查代码,并尝试找出您释放了多少次。阻止这种情况的一种方法是在释放它指向的块后立即将指针设置为零。

      另一种可能性是,您没有使用 msvcrt,并且正在加载一个也不使用 msvcrt 的 DLL,并且分配发生在可执行文件或 DLL 中,并在另一个中释放。

      【讨论】:

      • 我会检查我所有的删除,堆栈回溯说它在我的 RakNet.dll 中,可能是这种情况
      猜你喜欢
      • 2018-09-19
      • 2010-11-27
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      相关资源
      最近更新 更多