Boost C++ Libraries: Ticket #13259: seg fault at cleanup time, __run_exit_handlers https://svn.boost.org/trac10/ticket/13259 <p> I am getting a segfault at <span class="underline">run_exit_handlers time with 1.66 develop commit id d21a064a69663faf106ea363bf4785904bfd44d1 (Oct 6) using build command </span></p> <p> <code>~/boost/libs/serialization/test$ ../../../b2 toolset=clang test_dll_exported -q</code>: </p> <pre class="wiki">==13247== Invalid free() / delete / delete[] / realloc() ==13247== at 0x4C2F25B: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==13247== by 0x50A097F: __gnu_cxx::new_allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::deallocate(std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*, unsigned long) (new_allocator.h:110) ==13247== by 0x50A092F: __gnu_cxx::__alloc_traits&lt;std::allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt; &gt;::deallocate(std::allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;&amp;, std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*, unsigned long) (alloc_traits.h:133) ==13247== by 0x50A07CB: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_put_node(std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*) (stl_tree.h:509) ==13247== by 0x50A071B: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_drop_node(std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*) (stl_tree.h:576) ==13247== by 0x50A127B: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_erase_aux(std::_Rb_tree_const_iterator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;) (stl_tree.h:2275) ==13247== by 0x50A1234: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::erase(std::_Rb_tree_const_iterator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;) (stl_tree.h:1057) ==13247== by 0x509FF64: std::multiset&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::erase(std::_Rb_tree_const_iterator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;) (stl_multiset.h:571) ==13247== by 0x509FB97: boost::serialization::typeid_system::extended_type_info_typeid_0::type_unregister() (extended_type_info_typeid.cpp:108) ==13247== by 0x4205E4: boost::serialization::extended_type_info_typeid&lt;polymorphic_derived2&gt;::~extended_type_info_typeid() (extended_type_info_typeid.hpp:96) ==13247== by 0x420134: boost::serialization::singleton&lt;boost::serialization::extended_type_info_typeid&lt;polymorphic_derived2&gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() (singleton.hpp:117) ==13247== by 0x601B26F: __run_exit_handlers (exit.c:83) ==13247== Address 0x63b9d80 is 0 bytes inside a block of size 40 free'd ==13247== at 0x4C2F25B: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==13247== by 0x50A097F: __gnu_cxx::new_allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::deallocate(std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*, unsigned long) (new_allocator.h:110) ==13247== by 0x50A092F: __gnu_cxx::__alloc_traits&lt;std::allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt; &gt;::deallocate(std::allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;&amp;, std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*, unsigned long) (alloc_traits.h:133) ==13247== by 0x50A07CB: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_put_node(std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*) (stl_tree.h:509) ==13247== by 0x50A071B: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_drop_node(std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*) (stl_tree.h:576) ==13247== by 0x50A0647: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_erase(std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;*) (stl_tree.h:1640) ==13247== by 0x50A05BE: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::~_Rb_tree() (stl_tree.h:873) ==13247== by 0x50A0584: std::multiset&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::~multiset() (stl_multiset.h:92) ==13247== by 0x50A0414: boost::serialization::singleton&lt;std::multiset&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() (singleton.hpp:117) ==13247== by 0x601B5E9: __cxa_finalize (cxa_finalize.c:56) ==13247== by 0x5087F12: ??? (in /home/jking/boost/bin.v2/libs/serialization/build/clang-gnu-linux-4.0.0/debug/threadapi-pthread/libboost_serialization.so.1.66.0) ==13247== by 0x4011109: _dl_fini (dl-fini.c:235) ==13247== Block was alloc'd at ==13247== at 0x4C2E19F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==13247== by 0x50A0FC0: __gnu_cxx::new_allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::allocate(unsigned long, void const*) (new_allocator.h:104) ==13247== by 0x50A0F6B: __gnu_cxx::__alloc_traits&lt;std::allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt; &gt;::allocate(std::allocator&lt;std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;&amp;, unsigned long) (alloc_traits.h:130) ==13247== by 0x50A0E43: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_get_node() (stl_tree.h:505) ==13247== by 0x50A0DFF: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_create_node(boost::serialization::typeid_system::extended_type_info_typeid_0 const* const&amp;) (stl_tree.h:527) ==13247== by 0x50A0D8F: std::_Rb_tree_node&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;* std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_Alloc_node::operator()&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;(boost::serialization::typeid_system::extended_type_info_typeid_0 const* const&amp;) const (stl_tree.h:473) ==13247== by 0x50A0BDB: std::_Rb_tree_iterator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_insert_&lt;std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_Alloc_node&gt;(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, boost::serialization::typeid_system::extended_type_info_typeid_0 const* const&amp;, std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_Alloc_node&amp;) (stl_tree.h:1535) ==13247== by 0x50A09FC: std::_Rb_tree&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::extended_type_info_typeid_0 const*, std::_Identity&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt;, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::_M_insert_equal(boost::serialization::typeid_system::extended_type_info_typeid_0 const* const&amp;) (stl_tree.h:1918) ==13247== by 0x509FE2C: std::multiset&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt;::insert(boost::serialization::typeid_system::extended_type_info_typeid_0 const* const&amp;) (stl_multiset.h:474) ==13247== by 0x509FA68: boost::serialization::typeid_system::extended_type_info_typeid_0::type_register(std::type_info const&amp;) (extended_type_info_typeid.cpp:91) ==13247== by 0x4201CA: boost::serialization::extended_type_info_typeid&lt;polymorphic_derived2&gt;::extended_type_info_typeid() (extended_type_info_typeid.hpp:91) ==13247== by 0x4200FE: boost::serialization::singleton&lt;boost::serialization::extended_type_info_typeid&lt;polymorphic_derived2&gt; &gt;::get_instance()::singleton_wrapper::singleton_wrapper() (singleton.hpp:117) </pre><p> In gdb it looks like this, not sure if it's the same thing however: </p> <pre class="wiki">(gdb) r Starting program: /home/jking/boost/bin.v2/libs/serialization/test/test_dll_exported.test/clang-gnu-linux-4.0.0/debug/threadapi-pthread/test_dll_exported No errors detected. Program received signal SIGSEGV, Segmentation fault. 0x00007ffff71f79b6 in std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&amp;) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (gdb) bt #0 0x00007ffff71f79b6 in std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&amp;) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #1 0x00007ffff793564b in std::_Rb_tree&lt;boost::serialization::extended_type_info const*, boost::serialization::extended_type_info const*, std::_Identity&lt;boost::serialization::extended_type_info const*&gt;, boost::serialization::detail::key_compare, std::allocator&lt;boost::serialization::extended_type_info const*&gt; &gt;::_M_erase_aux ( this=0x7ffff7b9e948 &lt;boost::serialization::singleton&lt;std::multiset&lt;boost::serialization::extended_type_info const*, boost::serialization::detail::key_compare, std::allocator&lt;boost::serialization::extended_type_info const*&gt; &gt; &gt;::get_instance()::t&gt;, __position=0x631870 &lt;boost::serialization::singleton&lt;boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt; &gt;::get_instance()::t&gt;) at /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_tree.h:2272 #2 0x00007ffff7935615 in std::_Rb_tree&lt;boost::serialization::extended_type_info const*, boost::serialization::extended_type_info const*, std::_Identity&lt;boost::serialization::extended_type_info const*&gt;, boost::serialization::detail::key_compare, std::allocator&lt;boost::serialization::extended_type_info const*&gt; &gt;::erase ( this=0x7ffff7b9e948 &lt;boost::serialization::singleton&lt;std::multiset&lt;boost::serialization::extended_type_info const*, boost::serialization::detail::key_compare, std::allocator&lt;boost::serialization::extended_type_info const*&gt; &gt; &gt;::get_instance()::t&gt;, __position=0x631870 &lt;boost::serialization::singleton&lt;boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt; &gt;::get_instance()::t&gt;) at /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_tree.h:1057 #3 0x00007ffff7934395 in std::multiset&lt;boost::serialization::extended_type_info const*, boost::serialization::detail::key_compare, std::allocator&lt;boost::serialization::extended_type_info const*&gt; &gt;::erase ( this=0x7ffff7b9e948 &lt;boost::serialization::singleton&lt;std::multiset&lt;boost::serialization::extended_type_info const*, boost::serialization::detail::key_compare, std::allocator&lt;boost::serialization::extended_type_info const*&gt; &gt; &gt;::get_instance()::t&gt;, __position=0x631870 &lt;boost::serialization::singleton&lt;boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt; &gt;::get_instance()::t&gt;) at /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_multiset.h:571 #4 0x00007ffff7933ec9 in boost::serialization::extended_type_info::key_unregister (this=0x631870 &lt;boost::serialization::singleton&lt;boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt; &gt;::get_instance()::t&gt;) at ../../../libs/serialization/src/extended_type_info.cpp:136 #5 0x000000000041fed7 in boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt;::~extended_type_info_no_rtti ( this=0x631870 &lt;boost::serialization::singleton&lt;boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt; &gt;::get_instance()::t&gt;) at ../../../boost/serialization/extended_type_info_no_rtti.hpp:107 #6 0x000000000041fa05 in boost::serialization::singleton&lt;boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() ( this=0x631870 &lt;boost::serialization::singleton&lt;boost::serialization::extended_type_info_no_rtti&lt;polymorphic_base&gt; &gt;::get_instance()::t&gt;) at ../../../boost/serialization/singleton.hpp:117 #7 0x00007ffff68a3270 in __run_exit_handlers (status=0, listp=0x7ffff6c2a5d8 &lt;__exit_funcs&gt;, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:83 #8 0x00007ffff68a32ca in __GI_exit (status=&lt;optimized out&gt;) at exit.c:105 #9 0x00007ffff68893f8 in __libc_start_main (main=0x414660 &lt;main(int, char**)&gt;, argc=1, argv=0x7fffffffe2e8, init=&lt;optimized out&gt;, fini=&lt;optimized out&gt;, rtld_fini=&lt;optimized out&gt;, stack_end=0x7fffffffe2d8) at ../csu/libc-start.c:325 #10 0x00000000004143ca in _start () at ../../../boost/serialization/singleton.hpp:155 </pre><p> I don't think either of these issues specifically describes the memory leak in <a class="new ticket" href="https://svn.boost.org/trac10/ticket/13186" title="#13186: Bugs: Memory leak in serialization 1.65 (new)">#13186</a> (valgrind is reporting that too) which is why I am opening a new defect for it. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13259 Trac 1.4.3