疑似std::regex_search正则匹配,导致堆栈错误
一个很奇怪的问题,当我_beginthreadex/CreateThread创建线程,使用std::regex_search匹配时,程序会崩溃,堆栈如下:
ntdll.dll!RtlReportCriticalFailure() 未知 ntdll.dll!RtlpHeapHandleError() 未知 ntdll.dll!RtlpHpHeapHandleError() 未知 ntdll.dll!RtlpLogHeapFailure() 未知 ntdll.dll!RtlpFreeHeapInternal() 未知 ntdll.dll!RtlFreeHeap() 未知 ucrtbase.dll!_free_base() 未知 > BD-Scan.exe!std::_Deallocate<16,0>(void * _Ptr, unsigned __int64 _Bytes) 行 255 C++ BD-Scan.exe!std::allocator<unsigned int>::deallocate(unsigned int * const _Ptr, const unsigned __int64 _Count) 行 798 C++ BD-Scan.exe!std::vector<unsigned int,std::allocator<unsigned int>>::_Tidy() 行 1754 C++ BD-Scan.exe!std::vector<unsigned int,std::allocator<unsigned int>>::~vector<unsigned int,std::allocator<unsigned int>>() 行 704 C++ BD-Scan.exe!std::_Vb_val<std::allocator<bool>>::~_Vb_val<std::allocator<bool>>() 行 2434 C++ BD-Scan.exe!std::vector<bool,std::allocator<bool>>::~vector<bool,std::allocator<bool>>() 行 2620 C++ BD-Scan.exe!std::_Bt_state_t<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>::~_Bt_state_t<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>() C++ BD-Scan.exe!std::_Tgt_state_t<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>::~_Tgt_state_t<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>() C++ BD-Scan.exe!std::_Matcher<std::_String_view_iterator<std::char_traits<char>>,char,std::regex_traits<char>,std::_String_view_iterator<std::char_traits<char>>>::_Do_if(std::_Node_if * _Node) 行 3126 C++ BD-Scan.exe!std::_Matcher<std::_String_view_iterator<std::char_traits<char>>,char,std::regex_traits<char>,std::_String_view_iterator<std::char_traits<char>>>::_Match_pat(std::_Node_base * _Nx) 行 3578 C++ BD-Scan.exe!std::_Matcher<std::_String_view_iterator<std::char_traits<char>>,char,std::regex_traits<char>,std::_String_view_iterator<std::char_traits<char>>>::_Match<std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>>(std::match_results<std::_String_view_iterator<std::char_traits<char>>,std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>> * _Matches, bool _Full_match) 行 1599 C++ BD-Scan.exe!std::_Matcher<std::_String_view_iterator<std::char_traits<char>>,char,std::regex_traits<char>,std::_String_view_iterator<std::char_traits<char>>>::_Match<std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>>(std::_String_view_iterator<std::char_traits<char>> _Pfirst, std::match_results<std::_String_view_iterator<std::char_traits<char>>,std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>> * _Matches, bool _Full_match) 行 1578 C++ BD-Scan.exe!std::_Regex_search2<std::_String_view_iterator<std::char_traits<char>>,std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>,char,std::regex_traits<char>,std::_String_view_iterator<std::char_traits<char>>>(std::_String_view_iterator<std::char_traits<char>> _First, std::_String_view_iterator<std::char_traits<char>> _Last, std::match_results<std::_String_view_iterator<std::char_traits<char>>,std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>> * _Matches, const std::basic_regex<char,std::regex_traits<char>> & _Re, std::regex_constants::match_flag_type _Flgs, std::_String_view_iterator<std::char_traits<char>> _Org) 行 2218 C++ BD-Scan.exe!std::regex_search<std::_String_view_iterator<std::char_traits<char>>,std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>,char,std::regex_traits<char>>(std::_String_view_iterator<std::char_traits<char>> _First, std::_String_view_iterator<std::char_traits<char>> _Last, std::match_results<std::_String_view_iterator<std::char_traits<char>>,std::allocator<std::sub_match<std::_String_view_iterator<std::char_traits<char>>>>> & _Matches, const std::basic_regex<char,std::regex_traits<char>> & _Re, std::regex_constants::match_flag_type _Flgs) 行 2243 C++ BD-Scan.exe!Scanner(_ONION_SCAN_OBJECT * pScanObject) 行 956 C++
但是当我不在CreateThread创建的线程中匹配,在程序主线程去匹配,就不会出现这个问题,很纳闷,怀疑是std::regex_search匹配导致了线程堆栈问题,暂时记录一下
最后改用boost库了,就没有这个问题了
std::string_view view((char*)pScanObject1->pFileMapAddress, (size_t)pScanObject1->ullFileMapSize); using SVMatchResults = std::match_results< std::string_view::const_iterator >; SVMatchResults mm; if (std::regex_search(view.begin(), view.end(), mm, re)) { std::cout << "matches!\n"; //return 0; }