Re: STL string assign异常
WinDbg
STL string assign异常
tonyYe
2012-09-18, 18:45 下午
哪位知道出现这样的堆栈是为什么:
STACK_TEXT:
WARNING: Stack unwind information not available. Following frames may be wrong.
10f3dda0 7c96b3e5 0ab65a08 000000a4 07dd0000 ntdll!DbgBreakPoint
10f3dfc8 7c98fb98 07dd0000 50000161 000000a4 ntdll!LdrAlternateResourcesEnabled+0x2ca6
10f3e04c 7c96b244 07dd0000 50000161 000000a4 ntdll!RtlpNtMakeTemporaryKey+0x749c
10f3e27c 7c939c0c 07dd0000 40000060 000000a4 ntdll!LdrAlternateResourcesEnabled+0x2b05
10f3e4b0 07b1e04e 07dd0000 40000060 000000a4 ntdll!RtlpUnWaitCriticalSection+0xad
10f3e4cc 07aef6a6 000000a4 d14f13ce 10f3e684 Camera!_heap_alloc_base+0x5e [f:\dd\vctools\crt_bld\self_x86\crt\src\malloc.c @ 105]
10f3e514 07aef42f 00000080 00000001 00000000 Camera!_heap_alloc_dbg_impl+0x1f6 [f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c @ 427]
10f3e534 07aef3cc 00000080 00000000 00000001 Camera!_nh_malloc_dbg_impl+0x1f [f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c @ 239]
10f3e55c 07aef351 00000080 00000000 00000001 Camera!_nh_malloc_dbg+0x2c [f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c @ 296]
10f3e57c 07a0e015 00000080 00000001 00000000 Camera!_malloc_dbg+0x21 [f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c @ 160]
10f3e598 079e68e1 00000080 10f3e76c 00000003 Camera!operator new+0x15 [f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxmem.cpp @ 347]
10f3e684 079e5fee 00000080 00000000 10f3e870 Camera!std::_Allocate<char>+0x61 [c:\program files\microsoft visual studio 9.0\vc\include\xmemory @ 43]
10f3e76c 079e5dd7 00000080 d14f1e5a 10f3e96c Camera!std::allocator<char>::allocate+0x2e [c:\program files\microsoft visual studio 9.0\vc\include\xmemory @ 145]
10f3e880 079e5ac3 0000007b 00000000 10f3ea60 Camera!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Copy+0xc7 [c:\program files\microsoft visual studio 9.0\vc\include\xstring @ 2093]
10f3e96c 079e4d1c 0000007b 00000000 10f3eb50 Camera!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Grow+0x53 [c:\program files\microsoft visual studio 9.0\vc\include\xstring @ 2123]
10f3ea60 079e3e55 10f3ec48 00000000 ffffffff Camera!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign+0x8c [c:\program files\microsoft visual studio 9.0\vc\include\xstring @ 1055]
10f3eb5c 079fd484 10f3ec48 d14f1a52 10f3ee94 Camera!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >+0x75 [c:\program files\microsoft visual studio 9.0\vc\include\xstring @ 724]
10f3ec88 079fd7a9 10f3ee60 00000000 cccccccc Camera!toLower+0xd4 [e:\tcom\camera\Camera\rtspurl1.cpp @ 61]
Re: STL string assign异常
uglyangel
2012-09-18, 19:35 下午
建议加一下符号,先看到栈底。
Re: STL string assign异常
tonyYe
2012-09-19, 11:16 上午
在100多个线程的情况下,使用STL的string来拼接字符串,比如string s= s1+" "+"dd"+s3+"tt";或者以下的代码:
string toLower(string str)
{
char* chartemp=(char*)malloc(str.length()+1);
memset(chartemp,0,str.length()+1);
memcpy(chartemp,str.c_str(),str.length());
strlwr(chartemp);
string lpUrl=chartemp;
free(chartemp);
return lpUrl;
}
这种情况下,这么用是不是很容易出错啊?
Re: STL string assign异常
格蠹老雷
2012-09-25, 21:47 下午
lpUrl是定义在栈上的局部变量,函数返回后就被析构了,对应的字符串buffer会被释放...父函数中再使用这个对象时,就是典型的使用已经释放的内存。不应该这样写。
Re: STL string assign异常
kkindof
2012-09-25, 22:52 下午
不是这个原因吧?string不是支持那什么复制拷贝吗?