0

This code bellow works fine on ubuntu/suse/redhat... but it crashs on debian, it is doing free on an invalid pointer

uname -a": Linux DEV20V 4.9.0-7-amd64 #1 SMP Debian 4.9.110-3+deb9u2 (2018-08-13) x86_64 GNU/Linux GLIBC: Debian GLIBC 2.24-11+deb9u3

Code

   boost::log::core::get()->add_thread_attribute("File", boost::log::attributes::mutable_constant<std::string>(""));
   boost::log::core::get()->add_thread_attribute("Line", boost::log::attributes::mutable_constant<int>(0));

   auto log_open_mode = std::ios_base::out;
   if (debug)
   {
      log_open_mode |= std::ios_base::trunc;
   }
   else
   {
      log_open_mode |= std::ios_base::app;
   }

   boost::shared_ptr< boost::log::core > core = boost::log::core::get();
   boost::shared_ptr< boost::log::sinks::text_file_backend > backend = boost::make_shared<boost::log::sinks::text_file_backend>();

//   boost::log::keywords::file_name = "file%N.log",
//   boost::log::keywords::open_mode = log_open_mode,
//   boost::log::keywords::rotation_size = 10 * 1024 * 1024,
//   boost::log::keywords::auto_flush = true


   backend->set_file_name_pattern("/var/log/file.log");
   backend->set_open_mode(log_open_mode);
   backend->set_rotation_size(10 * 1024 *1024);
   backend->auto_flush(true);

   typedef boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend > sink_t;
   boost::shared_ptr< sink_t > sink(new sink_t(backend));

   if (!debug)
   {
      sink->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
   }

   sink->set_formatter(
         boost::log::expressions::format("%1%: [%2%] [%3%:%4%] [pid-%5%] [t-%6% (%7%)] - %8%")
         % boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S")
         % boost::log::trivial::severity
         % boost::log::expressions::attr<std::string>("File")
         % boost::log::expressions::attr<int>("Line")
         % boost::log::expressions::attr<boost::log::attributes::current_process_id::value_type>("ProcessID")
         % boost::log::expressions::attr<boost::log::attributes::current_thread_id::value_type>("ThreadID")
         % a_thread_name
         % boost::log::expressions::smessage
   );

//   backend->scan_for_files(boost::log::sinks::file::scan_all);
   core->add_sink(sink);
   boost::log::add_common_attributes();

Stack trace

*** Error in `/usr/bin/lanctrlconfig': free(): invalid pointer: 0x00007ffe8fd61848 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7fcf822c6bfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7fcf822ccfc6]
/lib/x86_64-linux-gnu/libc.so.6(+0x7780e)[0x7fcf822cd80e]
/usr/lib/libboost_log.so.1.62.0(_ZN5boost3log11v2_mt_posix5sinks17text_file_backend30set_file_name_pattern_internalERKNS_10filesystem4pathE+0x179)[0x7fcf85479239]
/usr/lib/libboost_log.so.1.62.0(_ZN5boost3log11v2_mt_posix5sinks17text_file_backend9constructERKNS_10filesystem4pathESt13_Ios_OpenmodemRKNS1_3aux14light_functionIFbvEEEb+0x190)[0x7fcf8547a340]
/usr/lib/libboost_log.so.1.62.0(_ZN5boost3log11v2_mt_posix5sinks17text_file_backendC1Ev+0x53)[0x7fcf8547a463]
/usr/lib/liblanctrlcommon.so.1(_ZN5boost11make_sharedINS_3log11v2_mt_posix5sinks17text_file_backendEIEEENS_6detail15sp_if_not_arrayIT_E4typeEDpOT0_+0x6d)[0x7fcf83abd332]
/usr/lib/liblanctrlcommon.so.1(_Z8init_logRKSsb+0x28c)[0x7fcf83ab9ad5]
/usr/lib/liblanctrlcommon.so.1(_ZN3App5setupEiPPc+0x8a8)[0x7fcf83a44468]
/usr/bin/lanctrlconfig[0x490521]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7fcf822762e1]
/usr/bin/lanctrlconfig[0x4593ea]

Anyone could give some hint ?

EDIT Unmangled StackTrace (C++filt):

/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7fcf822c6bfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7fcf822ccfc6]
/lib/x86_64-linux-gnu/libc.so.6(+0x7780e)[0x7fcf822cd80e]
/usr/lib/libboost_log.so.1.62.0(boost::log::v2_mt_posix::sinks::text_file_backend::set_file_name_pattern_internal(boost::filesystem::path const&)+0x179)[0x7fcf85479239]
/usr/lib/libboost_log.so.1.62.0(boost::log::v2_mt_posix::sinks::text_file_backend::construct(boost::filesystem::path const&, std::_Ios_Openmode, unsigned long, boost::log::v2_mt_posix::aux::light_function<bool ()> const&, bool)+0x190)[0x7fcf8547a340]
/usr/lib/libboost_log.so.1.62.0(boost::log::v2_mt_posix::sinks::text_file_backend::text_file_backend()+0x53)[0x7fcf8547a463]
/usr/lib/liblanctrlcommon.so.1(boost::detail::sp_if_not_array<boost::log::v2_mt_posix::sinks::text_file_backend>::type boost::make_shared<boost::log::v2_mt_posix::sinks::text_file_backend>()+0x6d)[0x7fcf83abd332]
/usr/lib/liblanctrlcommon.so.1(init_log(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)+0x28c)[0x7fcf83ab9ad5]
/usr/lib/liblanctrlcommon.so.1(App::setup(int, char**)+0x8a8)[0x7fcf83a44468]
/usr/bin/lanctrlconfig[0x490521]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7fcf822762e1]
/usr/bin/lanctrlconfig[0x4593ea]
Bruno Romano
  • 303
  • 2
  • 10
  • Thanks, did it, added unmangled names. But still not solved. – Bruno Romano Oct 28 '19 at 21:02
  • 1
    It looks like liblanctrlcommon.so.1 is built in C++03 mode. Debian 9 ships with gcc 6, which defaults to C++14. Assuming that system Boost packages were built with default C++ settings, you may be having ABI incompatibility through `boost::filesystem::path`, which has an `std::string` data member. – Andrey Semashev Oct 28 '19 at 21:41
  • @AndreySemashev is it https://askubuntu.com/questions/770358/how-should-i-handle-abi-incompatability-between-gcc-4-9-and-gcc-5 something similiar right ? Thank you for helping, you give me a path to look. My last question, why last ubuntu didnt fail with this error ? – Bruno Romano Oct 28 '19 at 22:03
  • I don't know what you mean by "last ubuntu". Obviously, if it didn't crash then there's probably no mismatch between Boost and your code in terms of used ABI. Usually, you can see which ABI a binary uses in the symbol names it references. E.g. `std::__cxx11::basic_string` means the new C++11 and later ABI, and `std::basic_string` for the legacy C++03 ABI. – Andrey Semashev Oct 29 '19 at 17:50
  • Last ubuntu, I was trying to say last release, ubuntu 19.04 or 18.10, I had no problem with those versions, but I will see which ABI debian and ubuntu are using. Thank you. – Bruno Romano Oct 29 '19 at 18:38

1 Answers1

0

I had a similar problem.

My application either abort()ed (when using gperftools/tcmalloc) with a double free() or segfault's without tcmalloc, also somewhere in text_file_backend::set_file_name_pattern_internal

In my case it was sufficient to make Boost::filesystem an explicit link dependency (otherwise it was loaded by Boost::Log or Boost::Log::Setup library indirectly).

I tried Boost 1.69 and 1.71.0.