boost目录迭代器接收SIGABRT

boost目录迭代器接收SIGABRT,boost,sigabrt,boost-iterators,Boost,Sigabrt,Boost Iterators,我正在使用boost/filesystem迭代目录,并将它们添加到MacOSX+XCode3上的Zip文件中 我最初的逻辑是这样的 path targetDir( "Volumes/data/some_directory" ); directory_iterator it( targetDir ), eod; std::string filename; std::string strPath; // I tried both of two types of making loop for(

我正在使用boost/filesystem迭代目录,并将它们添加到MacOSX+XCode3上的Zip文件中

我最初的逻辑是这样的

path targetDir( "Volumes/data/some_directory" );
directory_iterator it( targetDir ), eod;

std::string filename;
std::string strPath;

// I tried both of two types of making loop
for( ; it != eod ; ++it )
{
    path const& p = *it;
    filename = p.filename();
    if( is_directory(p) )
    {
        strPath = strDirectory + filename + string("/");

        // Initially I wanted this logic to be recursive(these code block is a part of PackDirectory)
        PackDirectory( archive, strPath, lpszPackFile );
    }
    else if( is_regular_file(p) )
    {
        strPath = strDirectory + filename;
        // add this file to specified Zip file here
    }

}

then function returns here.
返回这个函数后,问题就出现了,我想,特别是在调用目录迭代器的析构函数时。它似乎删除了无效指针,并接收SIGABRT。 程序有时会像下面这样崩溃,有时当我点击step over时它会冻结,XCode说step over,但调用堆栈消失时不会继续。 关键是,即使我没有在循环中做任何事情,问题仍然存在,这意味着当变量被简单地创建并返回函数时

有关更多信息,当程序崩溃时,调用堆栈如下所示

#0  0x93f86c5a in __kill
#1  0x93f86c4c in kill$UNIX2003
#2  0x940195a5 in raise
#3  0x9402f6e4 in abort
#4  0x93f2c575 in free
#5  0x00134aea in dir_itr_close [inlined] at v2_operations.cpp:1300
#6  0x00134aea in ~dir_itr_imp [inlined] at operations.hpp:877
#7  0x00134aea in     checked_delete<boost::filesystem2::detail::dir_itr_imp<boost::filesystem2::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem2::path_traits> > > [inlined] at checked_delete.hpp:34
#8  0x00134aea in boost::detail::sp_counted_impl_p<boost::filesystem2::detail::dir_itr_imp<boost::filesystem2::basic_path<std::string, boost::filesystem2::path_traits> > >::dispose at v2_operations.cpp:78
#9  0x00136583 in boost::detail::sp_counted_base::weak_release at sp_counted_base_pt.hpp:97
它进入~dir_itr_imp,因此它似乎在通过类型检查后到达了正确的析构函数

目录迭代器有问题吗?
如果有人遇到此问题,请告诉我。

免费发出的信号不一定表示调用函数存在缺陷。较早且中断的free调用可能损坏了malloc的空闲内存列表,从而导致错误


尝试在valgrind中运行您的程序,它更健壮,并且在使用损坏的内存分配/释放时会立即消失。如果valgrind不是一个选项,您也可以尝试在单元测试中独立于程序的其余部分测试您的代码。

免费发出的信号不一定指向调用函数中的缺陷。较早且中断的free调用可能损坏了malloc的空闲内存列表,从而导致错误


尝试在valgrind中运行您的程序,它更健壮,并且在使用损坏的内存分配/释放时会立即消失。如果valgrind不是一个选项,您也可以尝试在单元测试中独立于程序的其余部分来测试代码。

这是XCode错误。有些断点与实际调试行不同,因此它会以某种方式删除目录迭代器两次。我现在正在将我的XCode更新为4.2。谢谢你的帮助,顺便说一句:这是XCode错误。有些断点与实际调试行不同,因此它会以某种方式删除目录迭代器两次。我现在正在将我的XCode更新为4.2。谢谢你的帮助,顺便说一句: