C++ boost.filesystem创建目录抛出std::bad\u alloc
我有一个VisualStudio2008C++03应用程序,它使用的是运行在WindowsXPSP3中的Boost1.47.0 调用C++ boost.filesystem创建目录抛出std::bad\u alloc,c++,windows,boost,boost-filesystem,C++,Windows,Boost,Boost Filesystem,我有一个VisualStudio2008C++03应用程序,它使用的是运行在WindowsXPSP3中的Boost1.47.0 调用boost::filesystem::create_目录(L“c:\\foo\\bar”)抛出一个std::bad_alloc异常 在输出窗口中,我看到一条调试堆消息:“heap[test.exe]:无效的分配大小-CDCDCDCE(超过7ffdeff)” callstack显示boost.filesystem正在创建一个新的区域设置和Microsoft标准库文件x
boost::filesystem::create_目录(L“c:\\foo\\bar”)代码>抛出一个std::bad_alloc
异常
在输出窗口中,我看到一条调试堆消息:“heap[test.exe]:无效的分配大小-CDCDCDCE(超过7ffdeff)”
callstack显示boost.filesystem正在创建一个新的区域设置和Microsoft标准库文件xlocale行309中最后一行可见的代码
msvcp90.dll!std::_Allocate<char>() + 0x17 bytes
msvcp90.dll!std::allocator<char>::allocate() + 0xf bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Copy() + 0x70 bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Grow() + 0x26 bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign() + 0x50 bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >() + 0x24 bytes
msvcp90.dll!std::locale::_Locimp::_Locimp() + 0x47 bytes
> test.exe!std::locale::locale<windows_file_codecvt>(const std::locale & _Loc={...}, const windows_file_codecvt * _Facptr=0x00b48f60) Line 309 + 0x69 bytes C++
test.exe!`anonymous namespace'::default_locale() Line 735 C++
test.exe!`anonymous namespace'::path_locale() Line 777 + 0x2a bytes C++
test.exe!boost::filesystem3::path::wchar_t_codecvt_facet() Line 797 + 0x25 bytes C++
test.exe!boost::filesystem3::path::codecvt() Line 388 + 0x5 bytes C++
test.exe!boost::filesystem3::path::path<wchar_t const *>(const wchar_t * begin=0x00b460f8, const wchar_t * end=0x00b46116) Line 162 + 0x5 bytes C++
test.exe!boost::filesystem3::path::parent_path() Line 313 + 0x57 bytes C++
test.exe!boost::filesystem3::detail::create_directories(const boost::filesystem3::path & p={...}, boost::system::error_code * ec=0x00000000) Line 832 + 0x13 bytes C++
test.exe!boost::filesystem3::create_directories(const boost::filesystem3::path & p={...}) Line 318 + 0x29 bytes C++
test.exe!wmain(int __formal=1, int __formal=1) Line 112 + 0xc bytes C++
test.exe!__tmainCRTStartup() Line 583 + 0x19 bytes C
test.exe!wmainCRTStartup() Line 403 C
kernel32.dll!_BaseProcessStart@4() + 0x23 bytes
msvcp90.dll!std::_Allocate()+0x17字节
msvcp90.dll!std::allocator::allocate()+0xf字节
msvcp90.dll!std::basic_字符串::_Copy()+0x70字节
msvcp90.dll!std::basic_字符串::_Grow()+0x26字节
msvcp90.dll!std::basic_string::assign()+0x50字节
msvcp90.dll!std::basic_string::basic_string()+0x24字节
msvcp90.dll!std::locale::_Locimp::_Locimp()+0x47字节
>test.exe!STD::LoaLe:Loistle(const STD:LoaLeCy= {…},const WistoSsFielfCoDeVT**FAPHPTR=0x00 B48 F60)行309 +0x69xByC++
test.exe`匿名命名空间::Debug TraseLeo()735行C++
test.exe`匿名命名空间::PATHOLACLE()行777 +0x2a字节C++
test.exe!BooSistEM3::路径::WCARTA TYCODEVTTFFACET()行797 +0x25字节C++
test.exe!BooSistEM3::路径::CODECVTH()行388 +0x5字节C++
test.exe!BooSistEM3::路径::路径(const WCHARGETT开始=0x00 B460F8,const WCHARYTT结束=0x00 B46116)行162 +0x5字节C++
test.exe!PosiSistEM3::路径:PARTRONPHATH()行313 +0x57字节C++
test.exe!BooSistEM3::细节:CurATEX目录(const Booo::FielSistEM3::PATH和P= {…},Booo:::Error代码:EC=0x90000)832 +0x13字节C++
test.exe!BooSistEM3::CurATEX目录(const Booo::FielSistEM3::Posi&P= {…})行318 +0x29字节C++
test.exe!WMIN(int y~正规=1,int y-形式=1)行112 +0xC字节C++
test.exe__tmainCRTStartup()行583+0x19字节C
test.exe!wmainCRTStartup()行403 C
内核32.dll_BaseProcessStart@4()+0x23字节
有人能建议如何解决这个问题吗
编辑我更新为boost 1.50.0。问题仍然存在。这似乎是Microsoft在运行调试版本时实现的std::locale
中的一个问题。报告于2012年6月发布
正如这个bug所描述的,您得到的关于内存地址CDCE的消息意味着访问已删除的内存
微软的网站目前还没有描述任何解决方案,但我建议尝试另一个方面,将L“c:\\foo\\bar”
更改为“c:\\foo\\bar”
这个问题闻起来像是\u SECURE\u SCL中的不匹配(或者可能有点相关的\u有迭代器\u调试
——但我怀疑后者,因为调用堆栈指示非调试构建)。请参阅以获取一些信息,并确保\u SECURE\u SCL
的构建中定义的方式与test.exe
和链接的boost文件系统库中定义的方式相同
好的,boost将使用VC默认值(即使在VS2008的版本中也是如此),因此,如果您正在设置\u SECURE\u SCL=0,这可能就是问题所在。宽字符和多字节字符的错误都是相同的。这与处于调试模式有关。发布版本没有显示此问题。该“0xCDCDCE”看起来像一个(主要是)对我来说,初始化数据模式是错误的。我想猜测一下,你有C++标准库头文件中的STD::Basic字符串的来源,所以你至少可以找出函数调用应该是什么,并将这些与实际检查寄存器或堆栈使用的那些进行比较,即使你与扩展O链接起来。f预构建库中的模板。为了消除明显的问题,您在这里使用的是所有内容的匹配调试构建?@Marko:在Visual Studio调试构建中,我认为未初始化字节设置为0xFE
,释放字节设置为0xCD
0xCD
是调试运行时用于分配的填充值未初始化的已删除内存。已删除的内存中填充了0xDD
:看起来一些未初始化的已分配数据项增加了。您可以发布一个小的复制实例吗?一个仅由boost::filesystem::create_目录(L“c:\\foo\\bar”)组成的程序
对我来说没有问题。你使用VS 2008时应用了SP1还是没有应用SP1?@MichaelBurr:我撒谎了。我的复制案例是在几个静态库中进行+链接。这些静态库是为发布模式编译的,并且链接了CRT的非调试版本。我添加了/NODEFAULTLIB:MSVCRT,msvcprt
以及所有这些eems现在可以工作了。作为最终解决方案,我将创建这些库的调试版本。我认为这是正确的。我正在将非调试库链接到调试版本。(请参阅上面的注释)