1

我遇到了无法调试的访问冲突。

我似乎在 CRT 调用中遇到了某种递归错误_CrtCheckMemory

以下是调用堆栈(底部-> 顶部),其中...刚刚删除了重复的消息。

msvcr100d.dll!__chkstk()    Unknown
msvcr100d.dll!_VCrtDbgReportA(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 252  C
msvcr100d.dll!_CrtDbgReportV(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 242   C
msvcr100d.dll!_CrtDbgReport(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, ...) Line 258   C
msvcr100d.dll!_CrtCheckMemory() Line 1817   C++
msvcr100d.dll!_heap_alloc_dbg_impl(unsigned __int64 nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 383 C++
msvcr100d.dll!_nh_malloc_dbg_impl(unsigned __int64 nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 239  C++
msvcr100d.dll!_calloc_dbg_impl(unsigned __int64 nNum, unsigned __int64 nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 601  C++
msvcr100d.dll!_getptd_noexit() Line 470 C
msvcr100d.dll!_XcptFilter(unsigned long xcptnum, _EXCEPTION_POINTERS * pxcptinfoptrs) Line 202  C
msvcr100d.dll!_callthreadstartex$filt$0() Line 316  C
msvcr100d.dll!__C_specific_handler(_EXCEPTION_RECORD * ExceptionRecord, void * EstablisherFrame, _CONTEXT * ContextRecord, _DISPATCHER_CONTEXT * DispatcherContext) C
ntdll.dll!0000000077989d0d()    Unknown
ntdll.dll!00000000779791af()    Unknown
ntdll.dll!00000000779b1278()    Unknown
msvcr100d.dll!__chkstk()    Unknown
...
msvcr100d.dll!_VCrtDbgReportA(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 298  C
msvcr100d.dll!_CrtDbgReportV(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 242   C
msvcr100d.dll!_CrtDbgReport(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, ...) Line 258   C
msvcr100d.dll!_CrtCheckMemory() Line 1817   C++
msvcr100d.dll!_heap_alloc_dbg_impl(unsigned __int64 nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 383 C++
msvcr100d.dll!_nh_malloc_dbg_impl(unsigned __int64 nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 239  C++
msvcr100d.dll!_calloc_dbg_impl(unsigned __int64 nNum, unsigned __int64 nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 601  C++
msvcr100d.dll!_getptd_noexit() Line 470 C
msvcr100d.dll!_errno() Line 280 C
msvcr100d.dll!_VCrtDbgReportA(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 298  C
msvcr100d.dll!_CrtDbgReportV(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 242   C
msvcr100d.dll!_CrtDbgReport(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, ...) Line 258   C
msvcr100d.dll!_CrtCheckMemory() Line 1817   C++
msvcr100d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1288   C++
msvcr100d.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265  C++
msvcr100d.dll!_freefls(void * data) Line 622    C
msvcr100d.dll!_freeptd(_tiddata * ptd) Line 683 C
msvcr100d.dll!_endthreadex(unsigned int retcode) Line 365   C
msvcr100d.dll!_callthreadstartex() Line 315 C
msvcr100d.dll!_threadstartex(void * ptd) Line 297   C
kernel32.dll!000000007729652d() Unknown
ntdll.dll!000000007798c521()    Unknown

任何想法可能导致此问题或有关如何进行调试的建议?

4

2 回答 2

4

嗯,有点悲剧。它试图生成一个诊断信息来告诉您堆已损坏。报告代码尝试获取errno的值以显示它,但这是一个按需分配的静态 CRT 变量。所以它分配内存。哪个死了,堆损坏了。这会触发诊断以告诉您堆已损坏。你可以猜到其余的,这个过程一直持续到堆栈用完。

一种解决方法是将这段代码添加到 main(或线程)的开头:

 int dummy = errno;

因此 CRT 在堆损坏之前分配内存。你仍然必须找到腐败的原因。

于 2012-10-02T19:08:53.430 回答
2

实际上,您的主要问题是您的内存已损坏,现在当程序要退出时,它想释放其内部分配的内存(用于存储每个线程数据的内存),并且由于您使用的是调试版本,因此它将检查其内存和了解失败并开始显示断言窗口,现在当它想要显示其断言窗口时,它需要分配一些内存并使用内存分配例程(在这种情况下malloc将转换为malloc_dbg)来分配其所需的内存和malloc_dbg检查内存状态并了解您的内存损坏并尝试再次显示断言窗口,此过程将重复。请检查您的动态内存分配(甚至检查静态定义的数组以进行覆盖)以解决您的内存损坏和堆栈溢出将自动解决

于 2012-10-02T18:50:53.433 回答