Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] 1.40 regex
From: John Maddock (john_at_[hidden])
Date: 2009-09-04 13:25:16


As I understand it, the error is coming from the shared_ptr default
constructor? If so that's outside of my control, but I can't see what the
problem could be either... unless there is some difference between how you
compiled the regex library, and how you compile your own code - are there
any changes in memory alignment or pointer sizes in the way you compile your
code?

>I have code that comes out clean in 1.39 (as unit-test and under
> valgrind), but under 1.40 it's not clean in valgrind and it crashes
> when run normally (malloc(): memory corruption). I'm trying to write
> a reproducer that is smaller than what I have, but incase something
> pops out at someone (or can point me where my code might be wrong),
> here is the valgrind output:
>
> Running 16 test cases...
> ==25074== Invalid write of size 8
> ==25074== at 0x4E7D4A8:
> boost::shared_ptr<boost::re_detail::named_subexpressions_base<char>
>>::shared_ptr() (shared_ptr.hpp:182)
> ==25074== by 0x4E813C1:
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> cons
> t*, std::string> > >
>>::match_results(std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > > const&) (match_results.hpp:77)
> ==25074== by 0x5811371:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator
> <char const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::construct_init(boost::basic_regex<char, boost::regex_traits<char,
> boost::cpp_rege
> x_traits<char> > > const&, boost::regex_constants::_match_flags)
> (perl_matcher_common.hpp:73)
> ==25074== by 0x4E856D2:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator
> <char const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::perl_matcher(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::_
> _normal_iterator<char const*, std::string>,
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_i
> terator<char const*, std::string> > > >&, boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags, _
> _gnu_cxx::__normal_iterator<char const*, std::string>)
> (perl_matcher.hpp:366)
> ==25074== by 0x4E8583A: bool
> boost::regex_search<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char
> const*, std::string>, __gnu_cxx::__normal_iterat
> or<char const*, std::string>,
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> c
> onst*, std::string> > > >&, boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags, __gnu_cxx::__no
> rmal_iterator<char const*, std::string>) (regex_search.hpp:55)
> ==25074== by 0x4E85BEF:
> boost::regex_token_iterator_implementation<__gnu_cxx::__normal_iterator<char
> const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex
> _traits<char> > >::init(__gnu_cxx::__normal_iterator<char const*,
> std::string>) (regex_token_iterator.hpp:109)
> ==25074== by 0x4E8AC07:
> boost::regex_token_iterator<__gnu_cxx::__normal_iterator<char const*,
> std::string>, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
> >::regex_token_iterator(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>,
> boost::basic_regex<char, boost::regex
> _traits<char, boost::cpp_regex_traits<char> > > const&, int,
> boost::regex_constants::_match_flags) (regex_token_iterator.hpp:200)
> ==25074== by 0x45D99C:
> application_ut_suite::test_logon::test_method()
> (application_ut.cpp:139)
> ==25074== Address 0x6a64588 is 0 bytes after a block of size 56 alloc'd
> ==25074== at 0x4C2506C: operator new(unsigned long) (in
> /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
> ==25074== by 0x5811362:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator
> <char const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::construct_init(boost::basic_regex<char, boost::regex_traits<char,
> boost::cpp_rege
> x_traits<char> > > const&, boost::regex_constants::_match_flags)
> (perl_matcher_common.hpp:73)
> ==25074== by 0x4E856D2:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator
> <char const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::perl_matcher(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::_
> _normal_iterator<char const*, std::string>,
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_i
> terator<char const*, std::string> > > >&, boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags, _
> _gnu_cxx::__normal_iterator<char const*, std::string>)
> (perl_matcher.hpp:366)
> ==25074== by 0x4E8583A: bool
> boost::regex_search<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char
> const*, std::string>, __gnu_cxx::__normal_iterat
> or<char const*, std::string>,
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> c
> onst*, std::string> > > >&, boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags, __gnu_cxx::__no
> rmal_iterator<char const*, std::string>) (regex_search.hpp:55)
> ==25074== by 0x4E85BEF:
> boost::regex_token_iterator_implementation<__gnu_cxx::__normal_iterator<char
> const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex
> _traits<char> > >::init(__gnu_cxx::__normal_iterator<char const*,
> std::string>) (regex_token_iterator.hpp:109)
> ==25074== by 0x4E8AC07:
> boost::regex_token_iterator<__gnu_cxx::__normal_iterator<char const*,
> std::string>, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
> >::regex_token_iterator(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>,
> boost::basic_regex<char, boost::regex
> _traits<char, boost::cpp_regex_traits<char> > > const&, int,
> boost::regex_constants::_match_flags) (regex_token_iterator.hpp:200)
> ==25074== by 0x442E4F: application_ut_suite::(anonymous
> namespace)::Test_Setup::Test_Setup(std::istream&, unsigned long)
> (application_ut.cpp:96)
> ==25074== by 0x45D99C:
> application_ut_suite::test_logon::test_method()
> (application_ut.cpp:139)
> ==25074== by 0x45F620:
> _ZN20application_ut_suiteL18test_logon_invokerEv
> (application_ut.cpp:133)
> ==25074==
> ==25074== Invalid write of size 8
> ==25074== at 0x46CE8A: boost::detail::shared_count::shared_count()
> (shared_count.hpp:71)
> ==25074==:regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> int, boost::regex_constants::_match_flags)
> (regex_token_iterator.hpp:200)
> ==25074== by 0x442E4F: application_ut_suite::(anonymous
> namespace)::Test_Setup::Test_Setup(std::istream&, unsigned long)
> (application_ut.cpp:96)
> ==25074== Address 0x6a64590 is 8 bytes after a block of size 56 alloc'd
> ==25074== at 0x4C2506C: operator new(unsigned long) (in
> /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
> ==25074== by 0x5811362:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::construct_init(boost::basic_regex<char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags) (perl_matcher_common.hpp:73)
> ==25074== by 0x4E856D2:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::perl_matcher(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>,
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::_cxx::__normal_iterator<char const*, std::string>,
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > > >&, boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags,
> __gnu_cxx::__normal_iterator<char const*, std::string>)
> (regex_search.hpp:55)
> ==25074== by 0x4E85BEF:
> boost::regex_token_iterator_implementation<__gnu_cxx::__normal_iterator<char
> const*, std::string>, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::init(__gnu_cxx::__normal_iterator<char const*, std::string>)
> (regex_token_iterator.hpp:109)
> ==25074== by 0x4E8AC07:
> boost::regex_token_iterator<__gnu_cxx::__normal_iterator<char const*,
> std::string>, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::regex_token_iterator(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>,
> boost::basic_regex<char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > > const&, int,
> boost::regex_constants::_match_flags) (regex_token_iterator.hpp:200)
> ==25074== by 0x442E4F: application_ut_suite::(anonymous
> namespace)::Test_Setup::Test_Setup(std::istream&, unsigned long)
> (application_ut.cpp:96)
> ==25074== by 0x45D99C:
> application_ut_suite::test_logon::test_method()
> (application_ut.cpp:139)
> ==250ub_match<__gnu_cxx::__normal_iterator<char const*, std::string> >
>>, boost::regex_traits<char, boost::cpp_regex_traits<char> >
>>::construct_init(boost::basic_regex<char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags) (perl_matcher_common.hpp:73)
> ==25074== by 0x4E856D2:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::perl_matcher(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>,
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > > >&, boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags,
> __gnu_cxx::__normal_iterator<char const*, std::string>)
> (perl_matcher.hpp:366)
> ==25074== by 0x4E8583A: bool
> boost::regex_search<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char
> const*, std::string>, __gnu_cxx::__normal_iterator<char const*,
> std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > > >&, boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
> boost::regex_constants::_match_flags,
> __gnu_cxx::__normal_iterator<char const*, std::string>)
> (regex_search.hpp:55)
> ==25074== by 0x4E85BEF:
> boost::regex_token_iterator_implementation<__gnu_cxx::__normal_iterator<char
> const*, std::string>, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::init(__gnu_cxx::__normal_iterator<char const*,
> snstants::_match_flags) (regex_token_iterator.hpp:200)
> ==25074== by 0x442E4F: application_ut_suite::(anonymous
> namespace)::Test_Setup::Test_Setup(std::istream&, unsigned long)
> (application_ut.cpp:96)
> ==25074== by 0x45D99C:
> application_ut_suite::test_logon::test_method()
> (application_ut.cpp:139)
> ==25074== by 0x45F620:
> _ZN20application_ut_suiteL18test_logon_invokerEv
> (application_ut.cpp:133)
> ==25074== Address 0x6a64598 is not stack'd, malloc'd or (recently) free'd
> **25074** new/new[] failed and should throw an exception, but Valgrind
> cannot throw exceptions and so is aborting instead. Sorry.
> ==25074== at 0x4C22E23: (within
> /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
> ==25074== by 0x4C250C8: operator new(unsigned long) (in
> /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
> ==25074== by 0x4E84680:
> __gnu_cxx::new_allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >::allocate(unsigned long, void const*)
> (new_allocator.h:92)
> ==25074== by 0x4E846AF:
> std::_Vector_base<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> >,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > > >::_M_allocate(unsigned long)
> (stl_vector.h:144)
> ==25074== by 0x4E8A4AE:
> std::vector<boost::sub_match<__gnu_cxx::__normal_iterator<char const*,
> std::string> >,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*tor.tcc:395)
> ==25074== by 0x4E8A61E:
> std::vector<boost::sub_match<__gnu_cxx::__normal_iterator<char const*,
> std::string> >,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >
>>::insert(__gnu_cxx::__normal_iterator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> >*,
> std::vector<boost::sub_match<__gnu_cxx::__normal_iterator<char const*,
> std::string> >,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > > > >, unsigned long,
> boost::sub_match<__gnu_cxx::__normal_iterator<char const*,
> std::string> > const&) (stl_vector.h:792)
> ==25074== by 0x4E8A73B:
> boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > > >::set_size(unsigned long,
> __gnu_cxx::__normal_iterator<char const*, std::string>,
> __gnu_cxx::__normal_iterator<char const*, std::string>)
> (match_results.hpp:399)
> ==25074== by 0x4E8B1BF:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > >::find_imp()
> (perl_matcher_common.hpp:263)
> ==25074== by 0x5810D0A:
> boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > >::find()
> (perl_matcher_common.hpp:229)
> ==25074== by 0x4E85846: bool
> boost::regex_search<__gnu_cxx::__normal_iterator<char const*,
> std::string>,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::string> > >, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char
> const*, std::string>, __gnu_cxx::__normal_iterator<char const*,
> std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char
> const*, std::string>, std::allocator<boost:::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::init(__gnu_cxx::__normal_iterator<char const*, std::string>)
> (regex_token_iterator.hpp:109)
> ==25074== by 0x4E8AC07:
> boost::regex_token_iterator<__gnu_cxx::__normal_iterator<char const*,
> std::string>, char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
>>::regex_token_iterator(__gnu_cxx::__normal_iterator<char const*,
> std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>,
> boost::basic_regex<char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > > const&, int,
> boost::regex_constants::_match_flags) (regex_token_iterator.hpp:200)
> ==25074==
> ==25074== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 3 from 1)
> ==25074== malloc/free: in use at exit: 64,694 bytes in 500 blocks.
> ==25074== malloc/free: 590 allocs, 89 frees, 103,110 bytes allocated.
> ==25074== For counts of detected errors, rerun with: -v
> ==25074== searching for pointers to 500 not-freed blocks.
> ==25074== checked 402,856 bytes.
> ==25074==
> ==25074== LEAK SUMMARY:
> ==25074== definitely lost: 0 bytes in 0 blocks.
> ==25074== possibly lost: 7,480 bytes in 190 blocks.
> ==25074== still reachable: 57,214 bytes in 310 blocks.
> ==25074== suppressed: 0 bytes in 0 blocks.
> ==25074== Rerun with --leak-check=full to see details of leaked memory.
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost

--------------------------------------------------------------------------------

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.409 / Virus Database: 270.13.76/2343 - Release Date: 09/03/09
05:50:00


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk