vector new char* 程序崩溃
bool CHtmlHelper::FindUrlEnd( char *& str,std::vector<char*>&vec){ try { if(*str == 0) { return false ; } char * strUrl = (char*)HeapAlloc(GetProcessHeap(), 0,128); if(strUrl == NULL) return false; memset(strUrl,0,128); char * pOut = strUrl; bool pStart = true; if(*str=='\"'||*str=='\'') { str++; true; } else { pStart = false; } int t = 0; int level = 0; while(*str!='\0'&&pOut != NULL) { if(pStart&&((*str)=='\"'||(*str)=='\'')) { break; } else if(!pStart &&(*str)=='>') { break; } if(*str=='/') level++; if(level == 3) break; *pOut = *str; pOut++; str++; t++; if(t >= 127) break; } if(level ==3) { if(FilterUrl(strUrl)) vec.push_back(strUrl); //在这里崩溃了 } else { //释放内存 BOOL bRes = ::HeapFree(GetProcessHeap(), 0, strUrl); if (bRes != TRUE) { OutputDebugString(L"释放内存出错/r/n"); } } } catch(std::exception &e) { std::cerr << " FindUrlEnd Caught exception:"<<e.what()<< std::endl; return false; } return true;;}ntdll.dll!7c938f01() > msvcr90d.dll!operator new(unsigned int size=376) 行59 + 0x9 字节 C++ anlili.exe!std::_Allocate<char *>(unsigned int _Count=94, char * * __formal=0x00000000) 行43 + 0xc 字节 C++ anlili.exe!std::allocator<char *>::allocate(unsigned int _Count=94) 行145 + 0xb 字节 C++ anlili.exe!std::vector<char *,std::allocator<char *> >::_Insert_n(std::_Vector_const_iterator<char *,std::allocator<char *> > _Where=0xfdfdfdfd <错误的指针>, unsigned int _Count=1, char * const & _Val=0x0015b6f0) 行1178 + 0xf 字节 C++ anlili.exe!std::vector<char *,std::allocator<char *> >::insert(std::_Vector_const_iterator<char *,std::allocator<char *> > _Where=0xfdfdfdfd <错误的指针>, char * const & _Val=0x0015b6f0) 行878 C++ anlili.exe!std::vector<char *,std::allocator<char *> >::push_back(char * const & _Val=0x0015b6f0) 行823 + 0x58 字节 C++ anlili.exe!CHtmlHelper::FindUrlEnd(char * & str=0x00e257a5, std::vector<char *,std::allocator<char *> > & vec=[63](0x00165460 "http://i1.sinaimg.cn",0x001654f8 "http://www.sina.com.cn",0x00165590 "http://sports.sina.com.cn",0x00165628 "http://blog.sina.com.cn",0x001656c0 "http://news.sina.com.cn",0x00165758 "http://www.sina.com.cn",0x001657f0 "http://sports.sina.com.cn",0x00165888 "https://login.sina.com.cn",0x00165920 "http://news.sina.com.cn",0x001659b8 "http://mil.news.sina.com.cn",0x00165a50 "http://n,...)) 行325 C++
FilterUrl(strUrl)
[解决办法]
采用内存错误检查工具,如valgrind检查一下,看检测到什么错误报告,然后针对性看看代码,一般可以解决问题。