Boost logo

Boost Users :

Subject: [Boost-users] [boost.interprocess] Construct boost::basic_string with managed_shared_memory as memory soure crash.
From: Zhiming Wang (forwzm_at_[hidden])
Date: 2018-08-02 09:31:31


Hi,

I am using boost 1.65.1 interprocess lib, and tried to construct a string
that is safe to store in a managed_shared_memory.

Types are defined as below:

 using namespace boost::interprocess;
 using ShmSegment_t = boost::interprocess::managed_shared_memory;

 using SegmentMgr_t =
boost::interprocess::managed_shared_memory::segment_manager;

 template <typename T>

 using Allocator_t = boost::interprocess::allocator<T, SegmentMgr_t>;

 using String_t = boost::interprocess::basic_string<char,
std::char_traits<char>, Allocator_t<char>>;

Code in problem is as below:

using namespace boost::interprocess;
ShmSegment_t segment(open_or_create, "Test", 1L << 31);
const std::string stdStr("std_str");
String_t ipcStr( stdStr.c_str(), segment.get_segment_manager()); *// oops,
crashed! *

Crash backtrace is as below:

#0 0x00007ffff7ab735c in
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0ul>,
0ul>::get_size (this=0x441f0ff40024) at
/usr/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp:593
 #1 0x00007ffff7ab157a in
boost::interprocess::segment_manager_base<boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0ul>, 0u
l> >::get_size (this=0x441f0ff40024) at
/usr/include/boost/interprocess/segment_manager.hpp:113
#2 0x00007ffff7ab002d in boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0ul>, 0ul>,
boost::interprocess::iset_index> >::max_size (this=0x7fffeeffbe80) at
/usr/include/boost/interprocess/allocators/allocator.hpp:164
#3 0x00007ffff7aaf34d in
boost::container::allocator_traits<boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_fa
mily, boost::interprocess::offset_ptr<void, long, unsigned long, 0ul>,
0ul>, boost::interprocess::iset_index> > >::priv_max_size (a=...) at
/usr/include/boost/container/allocator_traits.hpp:397
#4 boost::container::allocator_traits<boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interproc
ess::offset_ptr<void, long, unsigned long, 0ul>, 0ul>,
boost::interprocess::iset_index> > >::max_size (a=...) at
/usr/include/boost/container/allocator_traits.hpp:331
#5
boost::container::container_detail::basic_string_base<boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_famil
y, boost::interprocess::offset_ptr<void, long, unsigned long, 0ul>, 0ul>,
boost::interprocess::iset_index> > >::max_size (this=0x7fffeeffbe80) at
/usr/include/boost/container/string.hpp:354
#6 0x00007ffff7aae68a in boost::container::basic_string<char,
std::char_traits<char>, boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boo
st::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long,
unsigned long, 0ul>, 0ul>, boost::interprocess::iset_index> > >::max_size
(this=0x7fffeeffbe80)
    at /usr/include/boost/container/string.hpp:1080
#7 0x00007ffff7aadb7a in boost::container::basic_string<char,
std::char_traits<char>, boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boo
st::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long,
unsigned long, 0ul>, 0ul>, boost::interprocess::iset_index> >
>::priv_reserve (this=0x7fffeeffbe80, res_arg=21,
    null_terminate=true) at /usr/include/boost/container/string.hpp:2777

#8 0x00007ffff7aad62a in boost::container::basic_string<char,
std::char_traits<char>, boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boo
st::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long,
unsigned long, 0ul>, 0ul>, boost::interprocess::iset_index> > >::reserve
(this=0x7fffeeffbe80, res_arg=21)
    at /usr/include/boost/container/string.hpp:1141

#9 0x00007ffff7aacbdf in boost::container::basic_string<char,
std::char_traits<char>, boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boo
st::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long,
unsigned long, 0ul>, 0ul>, boost::interprocess::iset_index> > >::assign
(this=0x7fffeeffbe80,
    first=0x7fff5c000d60 "std_str", last=0x7fff5c000d75 "") at
/usr/include/boost/container/string.hpp:1494
#10 0x00007ffff7aac719 in boost::container::basic_string<char,
std::char_traits<char>, boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boo
st::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long,
unsigned long, 0ul>, 0ul>, boost::interprocess::iset_index> >
>::basic_string (this=0x7fffeeffbe80,
    s=0x7fff5c000d60 "std_str", a=...) at
/usr/include/boost/container/string.hpp:741

I tried "p m_header" within GDB at
/usr/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp:593, and GDB
told me the memory is not accessable.
What's worse is that the issue seems not happening in very code path,
that's it sometimes works and sometimes fails.

Any insight is appreciated. Thanks.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net