Boost logo

Boost :

From: Dominik Stadler (dstadler_at_[hidden])
Date: 2003-11-20 10:03:19

In our code the regular expression library reports the following assertion on Linux in

Linux_Oracle_9.2.0.4_Debug:>TestRunner --dll=TestRegex

suite RegexTest started:
/dcaclearcase/vobs/eParty/STLport/stlport/stl/_alloc.c(105): STL error :
Size of block passed to deallocate() doesn't match block size
/dcaclearcase/vobs/eParty/STLport/stlport/stl/_alloc.c(105): STL assertion
failure: __real_p->_M_size == __n

A stack-trace looks like this:

0x413c6b11 in __kill () from /lib/i686/
(gdb) where
#0 0x413c6b11 in __kill () from /lib/i686/
#1 0x4003779b in raise (sig=6) at signals.c:65
#2 0x413c8092 in abort () at ../sysdeps/generic/abort.c:88
#3 0x0812a4dc in _STL::__list<_STL::basic_string<char, _STL::char_traits<char>, _STL::allocator<char> >, _STL::allocator<_STL::basic_string<char, _STL::char_traits<char>, _STL::allocator<char> > > >::begin (this=0x0) at debug/_debug.c:322
#4 0x0812a484 in _STL::__stl_debug_engine<bool>::_VerboseAssert (__expr=0x81ace1d "__real_p->_M_size == __n", __error_ind=22,
    __f=0x81acd80 "/dcaclearcase/vobs/eParty/STLport/stlport/stl/_alloc.c", __l=105) at debug/_debug.c:299
#5 0x0812c073 in _STL::__debug_alloc<_STL::__malloc_alloc<0> >::deallocate (__p=0x82af0c8, __n=2) at _alloc.c:105
#6 0x0819e904 in boost::detail::allocator<int>::deallocate (this=0x0, p=0x82af0c8, n=2) at detail/allocator.hpp:137
#7 0x08197a42 in boost::re_detail::_priv_match_data<boost::re_detail::mapfile_iterator, boost::detail::allocator<char> >::m_free (this=0x6af3e1dc)
    at regex_match.hpp:266
#8 0x0818b22f in boost::re_detail::_priv_match_data<boost::re_detail::mapfile_iterator, boost::detail::allocator<char> >::~_priv_match_data (
    this=0x6af3e1dc, __in_chrg=2) at regex_match.hpp:202
#9 0x08175e42 in unsigned int boost::re_detail::reg_grep2<bool (*), boost::re_detail::mapfile_iterator, char, boost::regex_traits<char>, boost::detail::allocator<char>, boost::detail::allocator<char> > (
    foo=0x81a2abc <fti::xscript::RegularExpression::MatchFileCallback(boost::match_results<boost::re_detail::mapfile_iterator, boost::detail::allocator<char> > const &)>, first=
      {<iterator<_STL::random_access_iterator_tag,char,int,char *,char &>> = {<No data fields>}, node = 0x82ec76c, file = 0x6af3e67c, offset = 1520}, last=
      {<iterator<_STL::random_access_iterator_tag,char,int,char *,char &>> = {<No data fields>}, node = 0x82ec76c, file = 0x6af3e67c, offset = 1520},
    e=@0x6af3e6bc, flags=772, a={<No data fields>}) at regex_match.hpp:1682
#10 0x081717aa in unsigned int boost::regex_grep<bool (*), boost::re_detail::mapfile_iterator, char, boost::regex_traits<char>, boost::detail::allocator<char> > (
    foo=0x81a2abc <fti::xscript::RegularExpression::MatchFileCallback(boost::match_results<boost::re_detail::mapfile_iterator, boost::detail::allocator<char> > const &)>, first={<iterator<_STL::random_access_iterator_tag,char,int,char *,char &>> = {<No data fields>}, node = 0x82ec760, file = 0x6af3e67c, offset = 0},
    last={<iterator<_STL::random_access_iterator_tag,char,int,char *,char &>> = {<No data fields>}, node = 0x82ec76c, file = 0x6af3e67c, offset = 1520},
    e=@0x6af3e6bc, flags=0) at regex_match.hpp:1903
#11 0x080e16f8 in fti::xscript::RegularExpression::CountInFile (this=0x6af3e8ac, Filename=@0x6af3e8dc, MatchesFound=@0x6af3e8a4)
    at util/RegularExpression.cpp:121
#12 0x080f1154 in fti::xscript::instruction::FindExpression::Execute (this=0x82ca9e0, Context=0x829d498) at instruction/FindExpression.cpp:92
#13 0x080b4b45 in fti::xscript::ExecutionThread::ThreadFunction (this=0x8299710) at engine/Thread.cpp:57
#14 0x080b442e in fti::xscript::GlobalThreadFunction (Argument=0x8299710) at engine/Thread.cpp:10
#15 0x40034c6f in pthread_start_thread (arg=0x6af3ebe0) at manager.c:284
#16 0x40034d5f in pthread_start_thread_event (arg=0x6af3ebe0) at manager.c:308

I debugged the problem, I think that this is a problem in the regex-library in
the allocator in the file boost/detail/allocator.hpp

in method deallocate(pointer p, size_type n) allocation is done with a
size of
         n * sizeof(value_type)
whereas deallocation is done with

This will be different as soon as value_type is not 1, in our case we have
"const char *" which is 4 byte.

This only happens when using STL and under #ifdef BOOST_HAVE_SGI_ALLOCATOR

When I change allocator.hpp to add "* sizeof(value_type)", our tests work

< alloc_type::deallocate((void*)p, n);

>         // dsta-11/20/2003: *sizeof() was missing and caused assertions on Linux
>          alloc_type::deallocate((void*)p, n * sizeof(value_type));

Boost list run by bdawes at, gregod at, cpdaniel at, john at