Boost logo

Boost Users :

Subject: [Boost-users] [spirit] [test] Double deletion with auto-registered test suite?
From: Alastair Rankine (arsptr_at_[hidden])
Date: 2009-09-15 07:02:29


My very simple test app (complete code below) is getting a possible
double-deletion error, and it seems to have something to do with Boost
Test auto-registration. Here's the error:

% ./spirit2
Running 2 test cases...

*** No errors detected
spirit2(55443) malloc: *** error for object 0x3000101700a10: pointer
being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
zsh: abort ./spirit2

Here's the stack trace:

(gdb) bt
#0 0x00007fff88021b91 in malloc_error_break ()
#1 0x00007fff87f4b083 in free ()
#2 0x000000010006c3ac in boost::unit_test::framework_impl::clear
(this=0x1000deec0) at framework.ipp:133
#3 0x000000010006c4aa in
boost::unit_test::framework_impl::~framework_impl (this=0x1000deec0) at
framework.ipp:122
#4 0x000000010006da1e in __tcf_1 () at framework.ipp:225
#5 0x00007fff87f57274 in __cxa_finalize ()
#6 0x00007fff87f5718c in exit ()
#7 0x000000010000b7bb in start () at unit_test_parameters.ipp:172

The code is compiled on MacOS X 10.6.1 with the supplied gcc 4.2
compiler. Using Boost 1.40.0 as installed by MacPorts.

The Spirit guys reckon there's no heap allocation at all within their
library, so that kindof points the finger at Boost Test. Also the
problem goes away if you comment out one of the test cases, or remove
the BOOST_AUTO_TEST_SUITE calls.

Unless I'm doing something obviously wrong...?

Help appreciated.

#define BOOST_TEST_MODULE spirit test
#include <boost/test/included/unit_test.hpp>

#include <boost/spirit/include/qi.hpp>

namespace qi = boost::spirit::qi;

template <typename Iterator>
struct MyGrammar : public qi::grammar<Iterator>
{
    MyGrammar()
        : MyGrammar::base_type(sp)
    {
        using boost::spirit::char_;

        sp = char_(' ');
    }

    qi::rule<Iterator> sp;
};

BOOST_AUTO_TEST_SUITE(SpiritTest)

BOOST_AUTO_TEST_CASE(Test1)
{
    MyGrammar<std::string::const_iterator> parser;
}

BOOST_AUTO_TEST_CASE(Test2)
{
    MyGrammar<std::string::const_iterator> parser;
}

BOOST_AUTO_TEST_SUITE_END()


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net