Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Test] valgrind complains about invalid reads
From: Peter Klotz (Peter.Klotz_at_[hidden])
Date: 2008-11-14 08:04:26


Boost 1.37.0, Linux, x86_64, gcc 4.1:

Valgrind 3.3.1 complains when running this simple test:

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE( test1 )
{
    BOOST_CHECK( 1 == 1 );
}

The valgrind messages:

==1836== Memcheck, a memory error detector.
==1836== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==1836== Using LibVEX rev 1854, a library for dynamic binary translation.
==1836== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==1836== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==1836== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==1836== For more details, rerun with: -v
==1836==
Running 1 test case...

*** No errors detected
==1836== Invalid read of size 8
==1836== at 0x41E41C: __tcf_1 (in RegressionTest)
==1836== by 0x3830632FA4: exit (in /lib64/libc-2.5.so)
==1836== by 0x383061D8BA: (below main) (in /lib64/libc-2.5.so)
==1836== Address 0x4c1ade0 is 40 bytes inside a block of size 48 free'd
==1836== at 0x4A0555C: operator delete(void*) (vg_replace_malloc.c:342)
==1836== by 0x42024C: std::_Rb_tree<unsigned long, std::pair<unsigned long const, boost::unit_test::test_unit*>, std::_Select1st<std::pair<unsigned long const, boost::unit_test::test_unit*> >, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, boost::unit_test::test_unit*> > >::erase(unsigned long const&) (in RegressionTest)
==1836== by 0x417C11: boost::unit_test::test_unit::~test_unit() (in RegressionTest)
==1836== by 0x41E41B: __tcf_1 (in RegressionTest)
==1836== by 0x3830632FA4: exit (in /lib64/libc-2.5.so)
==1836== by 0x383061D8BA: (below main) (in /lib64/libc-2.5.so)
==1836==
==1836== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 5 from 1)
==1836== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1836== malloc/free: 89 allocs, 89 frees, 38,935 bytes allocated.
==1836== For counts of detected errors, rerun with: -v
==1836== All heap blocks were freed -- no leaks are possible.

I was not able to figure out what valgrind is really complaining about.

The internal map of test units holds two entries. One corresponds to my BOOST_AUTO_TEST_CASE call (id=1), the other one seems to be used internally (id=65536).

Both are properly erased in deregister_test_unit() which is called by ~test_unit().

Maybe someone with a little bit more insight into Boost.Test is willing to look at this.

Regards, Peter.


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