2

我正在尝试将 OSX 中的 Boost iostream 库与 gcc 4.7 一起使用(因为我将使用 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下运行这个,stackframe如下

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> > ()

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

4

0 回答 0