2

ディレクトリを反復するために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.

この関数を返した後、特に directory_iterator のデストラクタが呼び出されたときに問題が発生すると思います。無効なポインタを削除し、SIGABRT を受け取っているようです。以下のようにプログラムがクラッシュすることもあれば、ステップ オーバーを押すとフリーズすることもあります。そして要点は、ループ内で何もしなくても問題が残るということです。つまり、変数が単純に作成され、関数が返される場合です。

詳細については、プログラムがクラッシュしたときのコール スタックは次のようになります。

#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 に入るので、型チェックをパスして正しいデストラクタにたどり着くようです。

directory_iterator で何か問題がありましたか? 誰かがこの問題を経験した場合は、私に知らせてください。

4

1 に答える 1

0

発生したシグナルは、free必ずしも呼び出し関数の欠陥を示しているわけではありません。以前の破損した への呼び出しがの空きメモリ リストfreeを破損しmalloc、それによってエラーが発生した可能性があります。

でプログラムを実行してみてくださいvalgrind。これはより堅牢であり、破損したメモリ割り当て/割り当て解除が使用されるとすぐに停止します。オプションがない場合valgrindは、プログラムの残りの部分とは別に、単体テストでコードをテストすることもできます。

于 2012-07-08T21:56:49.400 に答える