Opened 11 years ago

Closed 11 years ago

#6201 closed Bugs (wontfix)

managed_shared_memory construstor crashes

Reported by: djgaspa@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.47.0 Severity: Problem
Keywords: managed_shared_memory gcc optimization Cc:

Description

The following code crashes with segmentation fault when compiled with the symbol -DNDEBUG and optimization -O1 or -O2 or -O3 using gcc 4.6.1 from ubuntu oneiric.

int main(int argc, char** argv)
{
    namespace bi = boost::interprocess;
    const char* name = "foobar";
    bi::shared_memory_object::remove(name);
    bi::managed_shared_memory segment(bi::create_only, name, 10 * 1024 * 1024);
}

Without the NDEGUB symbol it always works. With NDEBUG it works only with -O0.

The call stack obtained with -O1 -g -DNDEBUG is the following:

Program received signal SIGSEGV, Segmentation fault.
get_color (n=<optimized out>) at /usr/include/boost/intrusive/detail/rbtree_node.hpp:136
136	   {  return (color)ptr_bit::get_bits(n->parent_);  }
(gdb) bt
#0  get_color (n=<optimized out>) at /usr/include/boost/intrusive/detail/rbtree_node.hpp:136
#1  boost::intrusive::rbtree_algorithms<boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true> >::rebalance_after_insertion (header=..., p=...)
    at /usr/include/boost/intrusive/rbtree_algorithms.hpp:855
#2  0x0000000000409445 in insert_equal_upper_bound<boost::intrusive::detail::key_nodeptr_comp<std::less<boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>::block_ctrl>, boost::intrusive::rbtree_impl<boost::intrusive::setopt<boost::intrusive::detail::base_hook_traits<boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>::block_ctrl, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0, boost::intrusive::default_tag, 3>, std::less<boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>::block_ctrl>, unsigned long, true> > > > (comp=..., new_node=..., h=...) at /usr/include/boost/intrusive/rbtree_algorithms.hpp:539
#3  boost::intrusive::rbtree_impl<boost::intrusive::setopt<boost::intrusive::detail::base_hook_traits<boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>::block_ctrl, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0, boost::intrusive::default_tag, 3>, std::less<boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>::block_ctrl>, unsigned long, true> >::insert_equal (this=0x7ffff6477038, value=<optimized out>)
    at /usr/include/boost/intrusive/rbtree.hpp:482
#4  0x0000000000409550 in insert (value=<optimized out>, this=<optimized out>) at /usr/include/boost/intrusive/set.hpp:1569
#5  boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>::priv_add_segment (this=<optimized out>, addr=<optimized out>, size=<optimized out>)
    at /usr/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp:538
#6  0x0000000000409725 in rbtree_best_fit (this=0x7ffff6477010, extra_hdr_bytes=104, size=10485744) at /usr/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp:374
#7  segment_manager_base (reserved_bytes=104, size=10485744, this=0x7ffff6477010) at /usr/include/boost/interprocess/segment_manager.hpp:96
#8  boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index>::segment_manager (this=0x7ffff6477010, size=10485744) at /usr/include/boost/interprocess/segment_manager.hpp:408
#9  0x000000000040a00b in create_impl (size=10485744, addr=0x7ffff6477010, this=0x7fffffffe0a0) at /usr/include/boost/interprocess/detail/managed_memory_impl.hpp:178
#10 operator() (created=true, size=10485744, addr=0x7ffff6477010, this=0x7fffffffe088) at /usr/include/boost/interprocess/detail/managed_memory_impl.hpp:735
#11 boost::interprocess::detail::managed_open_or_create_impl<boost::interprocess::shared_memory_object, true, true>::priv_open_or_create<boost::interprocess::detail::create_open_func<boost::interprocess::detail::basic_managed_memory_impl<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index, 16ul> > > (
    this=0x7fffffffe0a8, type=<optimized out>, id=<optimized out>, size=10485760, mode=<optimized out>, addr=0x0, perm=..., construct_func=...)
    at /usr/include/boost/interprocess/detail/managed_open_or_create_impl.hpp:374
#12 0x0000000000404bfb in managed_open_or_create_impl<boost::interprocess::detail::create_open_func<boost::interprocess::detail::basic_managed_memory_impl<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index, 16u> > > (construct_func=..., mode=boost::interprocess::read_write, id=@0x7fffffffe0f8, this=0x7fffffffe0a8, perm=..., addr=0x0, size=10485760)
    at /usr/include/boost/interprocess/detail/managed_open_or_create_impl.hpp:170
#13 basic_managed_shared_memory (perm=..., addr=0x0, size=10485760, name=0x40a8e8 "foobar", create_only=<optimized out>, this=0x7fffffffe0a0) at /usr/include/boost/interprocess/managed_shared_memory.hpp:90
#14 main (argc=<optimized out>, argv=<optimized out>) at /home/gaspa/programmazione/openni/main.cpp:25

Change History (3)

comment:1 by djgaspa@…, 11 years ago

I can confirm that exactly the same error happens on windows using the official Mingw32 4.6.1 compiler, with both boost 1.47.0 and 1.48.0. Seems to be something wrong with any gcc 4.6 series, when optimizing with the NDEBUG symbol.

IMHO it's a really critical bug!!

comment:2 by Ion Gaztañaga, 11 years ago

I can't reproduce the bug with MingGW and GCC 4.6.2, I'll keep investigating.

comment:3 by djgaspa@…, 11 years ago

Resolution: wontfix
Status: newclosed
Version: Boost 1.48.0Boost 1.47.0

I'm very sorry, for some strange reason I was still using 1.47.0 headers. The problem is there, but seems to be fixed in 1.48.0.

Note: See TracTickets for help on using tickets.