频繁new长时间后操作异常,跟debug版最大new次数限制有关!

本文记录了一个程序在长时间运行后出现异常的情况及调试过程。通过在内存分配函数_heap_alloc_dbg中设置断点并跟踪,发现异常源于频繁的内存分配操作导致特定请求编号触发的调试中断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Debug信息:

TESTAPPD! CallSETranslator(struct EHExceptionRecord *,struct EHRegistrationNode *,void *,void *,struct _s_FuncInfo const *,int,struct EHRegistrationNode *) + 197 bytes
TESTAPPD! __InternalCxxFrameHandler + 962 bytes
TESTAPPD! __InternalCxxFrameHandler + 894 bytes
TESTAPPD! __InternalCxxFrameHandler + 227 bytes
TESTAPPD! __CxxFrameHandler + 44 bytes
NTDLL! 77fbb272()
NTDLL! 77facc28()
NTDLL! 77f91bc6()
BCCORE! 0c067fa0()
_heap_alloc_dbg(unsigned int 37, int 1, const char * 0x00000000, int 0) line 378 + 9 bytes
_nh_malloc_dbg(unsigned int 37, int 1, int 1, const char * 0x00000000, int 0) line 248 + 21 bytes
_nh_malloc(unsigned int 37, int 1) line 197 + 19 bytes
operator new(unsigned int 37) line 24 + 11 bytes
BCCORE! 0c067fb4()
std::allocator<char>::allocate(unsigned int 33, const void * 0x00000000) line 59 + 25 bytes
std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Copy(unsigned int 9) line 526 + 17 bytes
std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Grow(unsigned int 9, unsigned char 1) line 568
std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & {0x06a95829 ""}, unsigned int 0, unsigned int 4294967295) line 128 + 16 bytes
std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & {0x06a95829 ""}) line 44 + 54 bytes
_MY_STRUCT::_MY_STRUCT(const _MY_STRUCT & {...}) + 222 bytes
APP_TASK::svc() line 249 + 18 bytes
ACED! 100dded1()
ACED! 100de7a7()
ACED! 100de6a4()
ACED! 10033256()
_threadstartex(void * 0x032dff78) line 227 + 13 bytes
KERNEL32! 77e6b3bc()

优快云有个帖子曾提到:

我的一个程序不停的转了两天 出了一个异常对话框 (unknowned software exception 0x800000003, address 0xxxxxxxxx),在那个地址加断点再跟踪,居然是在 dbgheap.c 中_heap_alloc_dbg() 的

static long _lRequestCurr = 1; /* Current request number */

_CRTIMP long _crtBreakAlloc = -1L; /* Break on allocation by request
number */
_heap_alloc_dbg()

...
lRequest = _lRequestCurr;
/* break into debugger at specific memory allocation */
if (lRequest == _crtBreakAlloc)
_CrtDbgBreak();
...

处,其实 _CrtDbgBreak() 的汇编就是一个 int 3.
但这个 int 3 吧 如果你是用 vc 转碰上了 也就是一个对话框( user breakpoint at address 0xxxxxxxxx )
如果是 F10 走的话连框都不出 但如果你不是用 vc 转而是执行你的程序 碰上 int 3 就会出异常( 要么终止要么调试那种);
而这个 _lRequestCurr 是调一次就加一的 从 1 加到 -1 也就是四十多亿次,
通过加断点来测量 我的程序一分钟就调了该函数 60 万次( 也就是调 New,我都没有显示的调 New,都是什么 CString std::string 调的 ),结果转了两天就出一个异常。
不知道大家碰到过这种情况没有。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值