使用Boost和OSX时出现malloc错误

时间:2012-09-18 03:47:49

标签: c++ macos boost malloc iostream

我正在尝试使用gcc 4.7在OSX中使用Boost iostream库(因为我将使用C ++ 11功能)。以下代码编译和链接,但在运行时失败:

#include <iostream>
#include <fstream>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>

int main(int argc, char** argv) {

  std::string fname(argv[1]);

  std::ifstream file(fname.c_str(), std::ios_base::in | std::ios_base::binary);
  try {
    boost::iostreams::filtering_istream in;
    in.push(boost::iostreams::gzip_decompressor());
    in.push(boost::iostreams::file_source(fname));
    for( std::string str; std::getline(in, str); ) {
      std::cout << "Processed line " << str << '\n';
    }
   }
   catch(const boost::iostreams::gzip_error& e) {
   std::cout << e.what() << '\n';
  }
}

出现以下错误:

MapProbesToGenes(70632) malloc: *** error for object 0x100168860: pointer being freed    was not allocated
*** set a breakpoint in malloc_error_break to debug

在GDB下运行,堆栈帧如下

Program received signal SIGABRT, Aborted.
0x00007fff8b0d0d46 in __kill ()
(gdb) bt
#0  0x00007fff8b0d0d46 in __kill ()
#1  0x00007fff88f52e1c in abort ()
#2  0x00007fff88f26989 in free ()
#3  0x00007fff84365e7c in std::string::reserve ()
#4  0x00007fff8436606e in std::string::push_back ()
#5  0x00007fff8436602d in std::string::operator+= ()
#6  0x000000010006f307 in boost::iostreams::detail::gzip_header::process (this=0x113e8, c=6 '\006') at gzip.cpp:100
#7  0x000000010000f435 in boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::read<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > ()
#8  0x000000010000f13e in boost::iostreams::detail::read_filter_impl<boost::iostreams::multichar_tag>::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >, boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > ()
#9  0x000000010000edd7 in boost::iostreams::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >, boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > ()
#10 0x000000010000e557 in boost::iostreams::detail::flt_wrapper_impl<boost::iostreams::input>::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >, boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > ()
#11 0x000000010000e1d8 in boost::iostreams::detail::concept_adapter<boost::iostreams::basic_gzip_decompressor<std::allocator<char> > >::read<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > ()
#12 0x000000010000d020 in boost::iostreams::detail::indirect_streambuf<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >, std::char_traits<char>, std::allocator<char>, boost::iostreams::input>::underflow ()
#13 0x00000001000be63a in std::getline<char, std::char_traits<char>, std::allocator<char> > ()

我在线搜索了很多,但我找不到一个解决这个问题的令人满意的解决方案。

0 个答案:

没有答案