[Boost.Test] Error: Non-aligned pointer being freed
Hello Boost Users, when running my unit tests on Mac OS X compiled with darwin gcc 4.2.1 for x86_64 I am getting the following error messages printed out even though no testing error were detected. As a side note running the same unit test on Windows MSVC 8 or Solaris gcc 3.2 succeeds without issues, so this seems to be either gcc 4.2 or Mac OS X specific. --------------- hauer@gandalf:~/dev/shark4/utils$ bin/darwin-4.2.1/debug/address-model-64/architecture-x86/shark-utilstest_d Running 51 test cases... *** No errors detected shark-utilstest_d(45498) malloc: *** error for object 0x3000100301fb0: Non-aligned pointer being freed (2) *** set a breakpoint in malloc_error_break to debug shark-utilstest_d(45498) malloc: *** error for object 0x30001003020c0: Non-aligned pointer being freed (2) *** set a breakpoint in malloc_error_break to debug shark-utilstest_d(45498) malloc: *** error for object 0x3000100302200: non-page-aligned, non-allocated pointer being freed *** set a breakpoint in malloc_error_break to debug --------------- I then ran the test through gdb and set a breakpoint at malloc_error_break and took a backtrace as shown below: ---------------- Starting program: /Users/hauer/dev/shark/utils/bin/darwin-4.2.1/debug/address-model-64/architecture-x86/shark-utilstest_d warning: posix_spawn failed, trying execvp, error: 86 Reading symbols for shared libraries ++++++.. done Breakpoint 1 at 0x7fff83745a51 Running 51 test cases... *** No errors detected pirate-utilstest_d(45520) malloc: *** error for object 0x3000100300630: Non-aligned pointer being freed (2) *** set a breakpoint in malloc_error_break to debug Breakpoint 1, 0x00007fff83745a51 in malloc_error_break () (gdb) bt #0 0x00007fff83745a51 in malloc_error_break () #1 0x00007fff83740ad0 in szone_error () #2 0x00000001001655f8 in boost::unit_test::framework_impl::clear (this=0x1001c7600) at impl/framework.ipp:133 #3 0x0000000100165728 in boost::unit_test::framework_impl::~framework_impl (this=0x1001c7600) at impl/framework.ipp:122 #4 0x0000000100160d82 in __tcf_1 () at impl/framework.ipp:222 #5 0x00007fff8369d3dc in __cxa_finalize () #6 0x00007fff8369d2f2 in exit () #7 0x0000000100000ceb in start () ------------------ This point to framework_impl's clean() method: ------------------ void clear() { while( !m_test_units.empty() ) { test_unit_store::value_type const& tu = *m_test_units.begin(); // the delete will erase this element from map if( test_id_2_unit_type( tu.second->p_id ) == tut_suite ) delete (test_suite const*)tu.second; else delete (test_case const*)tu.second; // <-- Line 133 } } ----------------- I think test_case's dtor was made public in 1.39 but I guess this did not fix the problem at hand. Regards, Sebastian
Hello Sebastian Sebastian Hauer wrote:
Hello Boost Users, when running my unit tests on Mac OS X compiled with darwin gcc 4.2.1 for x86_64 I am getting the following error messages printed out even though no testing error were detected. As a side note running the same unit test on Windows MSVC 8 or Solaris gcc 3.2 succeeds without issues, so this seems to be either gcc 4.2 or Mac OS X specific. This point to framework_impl's clean() method:
------------------ void clear() { while( !m_test_units.empty() ) { test_unit_store::value_type const& tu = *m_test_units.begin();
// the delete will erase this element from map if( test_id_2_unit_type( tu.second->p_id ) == tut_suite ) delete (test_suite const*)tu.second; else delete (test_case const*)tu.second; // <-- Line 133 } } -----------------
I think test_case's dtor was made public in 1.39 but I guess this did not fix the problem at hand.
The problem you are seeing is exactly the same I reported a while ago against Boost 1.37.0 (and it is still present in 1.39.0). Please have a look at this thread: http://www.nabble.com/-Boost.Test--valgrind-complains-about-invalid-reads-td... I finally proposed to rewrite framework_impl::clear() and to make the test_unit destructor virtual. This solves the valgrind issue in my test program. The original code tries hard to not destroy a derived class (test_suite, test_case) through a base class (test_unit) pointer in framework_impl::clear(). Doing so would require a virtual test_unit destructor. Regards, Peter.
Hello Peter,
On Sat, Jul 4, 2009 at 1:44 PM, Peter Klotz
The problem you are seeing is exactly the same I reported a while ago against Boost 1.37.0 (and it is still present in 1.39.0).
Please have a look at this thread:
http://www.nabble.com/-Boost.Test--valgrind-complains-about-invalid-reads-td...
I finally proposed to rewrite framework_impl::clear() and to make the test_unit destructor virtual. This solves the valgrind issue in my test program.
Thanks for the pointer. I looked at the code and thought the same thing when I saw the clean() method. I've changed the base class destructor to virtual and it took care of the issue. I've also reintroduced the static_constant template from 1.38 to prevent the 'defined but not used' warnings (see http://www.nabble.com/-test--gcc-4.2.1-unused-warnings-reappear-in-1.39-td24... ). Attached is a patch with all the changes I've applied to 1.39. Regards, Sebastian
Hello Sebastian
Hello Peter,
On Sat, Jul 4, 2009 at 1:44 PM, Peter Klotz
wrote: The problem you are seeing is exactly the same I reported a while ago against Boost 1.37.0 (and it is still present in 1.39.0).
Please have a look at this thread:
http://www.nabble.com/-Boost.Test--valgrind-complains-about-invalid-reads-td...
I finally proposed to rewrite framework_impl::clear() and to make the test_unit destructor virtual. This solves the valgrind issue in my test program.
Thanks for the pointer. I looked at the code and thought the same thing when I saw the clean() method. I've changed the base class destructor to virtual and it took care of the issue. I've also reintroduced the static_constant template from 1.38 to prevent the 'defined but not used' warnings (see http://www.nabble.com/-test--gcc-4.2.1-unused-warnings-reappear-in-1.39-td24... ). Attached is a patch with all the changes I've applied to 1.39.
So let's hope the patch finds its way into Boost SVN. Regards, Peter.
participants (2)
-
Peter Klotz
-
Sebastian Hauer