Boost C++ Libraries: Ticket #2216: segementation fault in type_unregister() https://svn.boost.org/trac10/ticket/2216 <p> Hi, </p> <p> I'm using the serialization lib in my project. With the new 1.36 release, the app causes a segmentation violation on exiting. This didn't happen with the 1.35 release. Here's the debuggers' backtrace output: </p> <p> <a class="missing ticket">#0</a> 0xb56aa663 in std::_Rb_tree_rebalance_for_erase () from /usr/lib/libstdc++.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> 0xb54bad48 in boost::serialization::detail::extended_type_info_typeid_0::type_unregister () from /opt/project/lib/libboost_serialization-mt.so <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2" title="#2: Bugs: list::size should be const (closed: fixed)">#2</a> 0x083e381c in ~extended_type_info_typeid (this=0x8504ab8) at /opt/project/include/boost/serialization/extended_type_info_typeid.hpp:80 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3" title="#3: Bugs: automatic conversion and overload proble (closed: fixed)">#3</a> 0x08168a54 in <span class="underline">tcf_801 () at /opt/project/include/boost/serialization/singleton.hpp:104 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4" title="#4: Bugs: any_ptr in any library documentation? (closed: Fixed)">#4</a> 0xb5521bcd in exit () from /lib/libc.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5" title="#5: Bugs: shared_ptr and self-owning objects (closed: Fixed)">#5</a> 0xb550bfa4 in </span>libc_start_main () from /lib/libc.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6" title="#6: Bugs: tie in utility.hpp and tuple.hpp clash. (closed: Duplicate)">#6</a> 0x0815a261 in _start () </p> <p> I haven't time to investigate this at the moment. So I'm using 1.35 for now. </p> <p> Best regards </p> <p> Jörg </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2216 Trac 1.4.3 anonymous Thu, 28 Aug 2008 22:35:42 GMT <link>https://svn.boost.org/trac10/ticket/2216#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2216#comment:1</guid> <description> <p> Replying to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2216" title="#2216: Bugs: segementation fault in type_unregister() (closed: fixed)">joerg.schmidt@methodpark.de</a>: </p> <blockquote class="citation"> <p> Hi, </p> <p> I'm using the serialization lib in my project. With the new 1.36 release, the app causes a segmentation violation on exiting. This didn't happen with the 1.35 release. Here's the debuggers' backtrace output: </p> <p> <a class="missing ticket">#0</a> 0xb56aa663 in std::_Rb_tree_rebalance_for_erase () from /usr/lib/libstdc++.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> 0xb54bad48 in boost::serialization::detail::extended_type_info_typeid_0::type_unregister () from /opt/project/lib/libboost_serialization-mt.so <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2" title="#2: Bugs: list::size should be const (closed: fixed)">#2</a> 0x083e381c in ~extended_type_info_typeid (this=0x8504ab8) at /opt/project/include/boost/serialization/extended_type_info_typeid.hpp:80 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3" title="#3: Bugs: automatic conversion and overload proble (closed: fixed)">#3</a> 0x08168a54 in <span class="underline">tcf_801 () at /opt/project/include/boost/serialization/singleton.hpp:104 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4" title="#4: Bugs: any_ptr in any library documentation? (closed: Fixed)">#4</a> 0xb5521bcd in exit () from /lib/libc.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5" title="#5: Bugs: shared_ptr and self-owning objects (closed: Fixed)">#5</a> 0xb550bfa4 in </span>libc_start_main () from /lib/libc.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6" title="#6: Bugs: tie in utility.hpp and tuple.hpp clash. (closed: Duplicate)">#6</a> 0x0815a261 in _start () </p> <p> I haven't time to investigate this at the moment. So I'm using 1.35 for now. </p> <p> Best regards </p> <p> Jörg </p> </blockquote> <p> I think I have found and fixed an issue with the type_unregister and key_unregister functions. The problem seems to be with the removal of items from the multiset containing them. The items are inserted into the multiset via ptr and sorted on fields m_key or m_ti respectively. When the items are deleted from the multiset, a lower/upper bound search is performed to find the range of keys which contain the specified value (m_key, m_ti) and then subsequently the iterators on that range are subject to: </p> <blockquote> <p> detail::ktmap::iterator start = x.lower_bound(this); detail::ktmap::iterator end = x.upper_bound(this); assert(start != end); </p> </blockquote> <blockquote> <p> <em> remove entry in map which corresponds to this type do{ </em></p> </blockquote> <blockquote> <blockquote> <p> if(this == *start){ </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> x.erase(start); break; </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <p> }while(++start != end); </p> </blockquote> <blockquote> <p> m_key = NULL; </p> </blockquote> <p> Note that it breaks after removing the first item. It then sets the key to NULL. This means that on subsequent compares inside the set, if there are other instances of this key (which are held via ptr), the value of m_key is NULL. Inside the key_compare there are assert statements to check that m_key isn't NULL... after that all hell breaks lose :D. </p> <p> The same pattern is in extended_type_info_typeid.cpp. I fixed my local copy by changing the loop to use: </p> <blockquote> <p> do{ </p> </blockquote> <blockquote> <blockquote> <p> if(this == *start){ </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> start = x.erase(start); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> } else { </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> ++start; </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <p> }while(start != end); </p> </blockquote> <p> So all copies of an item with the same m_key or m_ti value are removed. After that everything seemed to run fine. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Brandon Kohn</dc:creator> <pubDate>Thu, 28 Aug 2008 22:36:44 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2216 https://svn.boost.org/trac10/ticket/2216 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">extended_type_info_files.patch</span> </li> </ul> <p> Patches for extended_type_info_typeid.cpp and extended_type_info.cpp </p> Ticket Ryan Mulder <rjmyst3@…> Fri, 29 Aug 2008 15:10:42 GMT <link>https://svn.boost.org/trac10/ticket/2216#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2216#comment:2</guid> <description> <p> This is a duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2217" title="#2217: Bugs: serialization 1.36.0 extended_type_info exit issue(s) (closed: fixed)">#2217</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Fri, 05 Sep 2008 22:42:09 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2216#comment:3 https://svn.boost.org/trac10/ticket/2216#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> I believe I have addressed a coding error in the unregistering of types as DLLs are or main programs are unloaded. I've checked the fix in the trunk. However, none of the test platforms have manifested this error, so it will by up to you test this when it migrates to the release branch. </p> <p> Robert Ramey </p> Ticket