dimanche 22 octobre 2023

boost regex_replace intermittent SIGARBT in boost::shared_ptr __cxa_pure_virtual [closed]

I use boost_174, jemalloc 5.2.1 The crash backtrace is

#0  0x00007f6f5d766387 in raise () from /lib64/libc.so.6
#1  0x00007f6f5d767a78 in abort () from /lib64/libc.so.6
#2  0x00007f6f5e076a95 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007f6f5e074a06 in ?? () from /lib64/libstdc++.so.6
#4  0x00007f6f5e074a33 in std::terminate() () from /lib64/libstdc++.so.6
#5  0x00007f6f5e07559f in __cxa_pure_virtual () from /lib64/libstdc++.so.6
#6  0x0000000001181c97 in boost::detail::sp_counted_base::release (this=0x7f6f534835c0) at /opt/boost/include/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:120
#7  0x0000000001181d23 in boost::detail::shared_count::~shared_count (this=0x7f6f539941c0, __in_chrg=<optimized out>)
    at /opt/boost/include/boost/smart_ptr/detail/shared_count.hpp:432
#8  0x0000000001412ade in boost::shared_ptr<boost::re_detail_107400::named_subexpressions>::~shared_ptr (this=0x7f6f539941b8, __in_chrg=<optimized out>)
    at /opt/boost/include/boost/smart_ptr/shared_ptr.hpp:335
#9  0x0000000001412b6c in boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::~match_results (this=0x7f6f53994180, __in_chrg=<optimized out>) at /opt/boost/include/boost/regex/v4/match_results.hpp:119
#10 0x000000000148c416 in boost::regex_iterator_implementation<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::~regex_iterator_implementation (this=0x7f6f53994180, __in_chrg=<optimized out>) at /opt/boost/include/boost/regex/v4/regex_iterator.hpp:40
#11 0x000000000148c436 in boost::checked_delete<boost::regex_iterator_implementation<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > >
    (x=0x7f6f53994180) at /opt/boost/include/boost/core/checked_delete.hpp:36
#12 0x000000000148f152 in boost::detail::sp_counted_impl_p<boost::regex_iterator_implementation<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > >::dispose (this=0x7f6f53dccc40) at /opt/boost/include/boost/smart_ptr/detail/sp_counted_impl.hpp:89
#13 0x0000000001181c97 in boost::detail::sp_counted_base::release (this=0x7f6f53dccc40) at /opt/boost/include/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:120
#14 0x0000000001181d23 in boost::detail::shared_count::~shared_count (this=0x7ffc4e5a06e8, __in_chrg=<optimized out>)
    at /opt/boost/include/boost/smart_ptr/detail/shared_count.hpp:432
#15 0x000000000148996c in boost::shared_ptr<boost::regex_iterator_implementation<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > >::~shared_ptr (this=0x7ffc4e5a06e0, __in_chrg=<optimized out>) at /opt/boost/include/boost/smart_ptr/shared_ptr.hpp:335
#16 0x000000000148b129 in boost::shared_ptr<boost::regex_iterator_implementation<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > >::reset (this=0x7ffc4e5a07b0) at /opt/boost/include/boost/smart_ptr/shared_ptr.hpp:687
#17 0x000000000148a20d in boost::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::regex_iterator (this=0x7ffc4e5a07b0, 
    a=47 '/', b=0 '\000', re=..., m=boost::regex_constants::format_first_only) at /opt/boost/include/boost/regex/v4/regex_iterator.hpp:111
#18 0x0000000001495666 in boost::regex_replace<boost::re_detail_107400::string_out_iterator<std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::regex_traits<char, boost::cpp_regex_traits<char> >, char, std::string> (out=..., first=47 '/', last=0 '\000', e=..., fmt="/", flags=boost::regex_constants::format_first_only)
    at /opt/boost/include/boost/regex/v4/regex_replace.hpp:46
#19 0x0000000001494d31 in boost::regex_replace<boost::regex_traits<char, boost::cpp_regex_traits<char> >, char, std::string> (s="/si_er/frontend/dwr/table/init.action", e=..., fmt="/", 
    flags=boost::regex_constants::format_first_only) at /opt/boost/include/boost/regex/v4/regex_replace.hpp:80

frame info 
(gdb) frame 9
#9  0x0000000001412b6c in boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::~match_results (this=0x7f6f53994180, __in_chrg=<optimized out>) at /opt/boost/include/boost/regex/v4/match_results.hpp:119
119    ~match_results(){}
(gdb) p *this
$25 = {m_subs = std::vector of length 3, capacity 3 = {
    {<std::pair<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >> = {first = 0 '\000', second = 0 '\000'}, matched = false}, 
    {<std::pair<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >> = {first = 47 '/', second = 46 '.'}, matched = true}, 
    {<std::pair<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >> = {first = 46 '.', second = 0 '\000'}, matched = false}}, m_base = 47 '/', 
  m_null = {<std::pair<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >> = {first = <error reading variable: Cannot access memory at address 0x0>, m_named_subs = {px = 0x7f6f5380cf80, pn = {pi_ = 0x7f6f534835c0}}, 
  m_last_closed_paren = 0, m_is_singular = true}
(gdb) down
#8  0x0000000001412ade in boost::shared_ptr<boost::re_detail_107400::named_subexpressions>::~shared_ptr (this=0x7f6f539941b8, __in_chrg=<optimized out>)
    at /opt/boost/include/boost/smart_ptr/shared_ptr.hpp:335
335 template<class T> class shared_ptr
(gdb) p this
$26 = (boost::shared_ptr<boost::re_detail_107400::named_subexpressions> * const) 0x7f6f539941b8
(gdb) p *this
$27 = {px = 0x7f6f5380cf80, pn = {pi_ = 0x7f6f534835c0}}
(gdb) down
#7  0x0000000001181d23 in boost::detail::shared_count::~shared_count (this=0x7f6f539941c0, __in_chrg=<optimized out>)
    at /opt/boost/include/boost/smart_ptr/detail/shared_count.hpp:432
432         if( pi_ != 0 ) pi_->release();
(gdb) p pi_
$28 = (boost::detail::sp_counted_base *) 0x7f6f534835c0
(gdb) p *pi_
$29 = {_vptr.sp_counted_base = 0x2099fb0 <vtable for boost::detail::sp_counted_base+16>, use_count_ = 0, weak_count_ = 0}
(gdb) p *this
$30 = {pi_ = 0x7f6f534835c0}
(gdb) down
#6  0x0000000001181c97 in boost::detail::sp_counted_base::release (this=0x7f6f534835c0) at /opt/boost/include/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:120
120             dispose();
(gdb) p *this
$31 = {_vptr.sp_counted_base = 0x2099fb0 <vtable for boost::detail::sp_counted_base+16>, use_count_ = 0, weak_count_ = 0}

break code
release  m_named_subs pi_

boost/include/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:120
    void release() // nothrow
    {
        if( atomic_decrement( &use_count_ ) == 0 )
        {
            dispose(); //c
            weak_release();
        }
    }

I have written a demo to reproduce the issue. In my demo, the m_named_subs will not be release because use_count_ > 0.

I want to know if 'm_named_subs' should not be released. Also, why does '__cxa_pure_virtual' occur during 'boost::detail::sp_counted_base::release'?

Aucun commentaire:

Enregistrer un commentaire