
On Sep 21, 2009, at 1:20 PM, Peter Soetens wrote:
On Mon, Sep 21, 2009 at 22:06, Peter Klotz
wrote: Rush Manbert wrote:
On Sep 19, 2009, at 12:42 AM, Peter Klotz wrote:
Rush Manbert wrote:
On Sep 18, 2009, at 4:57 PM, Rush Manbert wrote:
On Sep 17, 2009, at 1:02 AM, Vrai Stacey wrote:
> Hi, > > I've been making my first forays in to using Boost on the new > OS X > release and have encountered some strange behaviour on 64bit > machines. > Testing with Boost 1.37.0 and 1.40.0 I've found that everything > compiles as expected, but attempting to run any unit tests > results in > an error of the form: > > *** No errors detected > test_exceptions(92517) malloc: *** error for object > 0x3000100200460: > pointer being freed was not allocated > *** set a breakpoint in malloc_error_break to debug > <snip>
I am seeing the same thing using Boost 1.38.0 built for 64-bit Intel on OS X 10.6.1. The test program worked fine on OS X 10.5.7, but I'm seeing the same malloc errors as you.
For me, the error occurs in the file framework.ipp:
class framework_impl : public test_tree_visitor { public: framework_impl() : m_master_test_suite( 0 ) , m_curr_test_case( INV_TEST_UNIT_ID ) , m_next_test_case_id( MIN_TEST_CASE_ID ) , m_next_test_suite_id( MIN_TEST_SUITE_ID ) , m_is_initialized( false ) , m_test_in_progress( false ) {}
~framework_impl() { clear(); }
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; <<<<------------------------- This statement generates the error } }
GDB won't let me put a breakpoint anywhere in this file. Maybe I can hack it to see something...
Okay, I was able to debug it by doing this: The main unit test file is called UnitTestMain.cpp, and just includes
, and that file includes all of the *.ipp files. I preprocessed UnitTestMain.cpp in Xcode and deleted all of the preprocessor lines with sed: sed '/^#/ d' UnitTestMain.cpp and I substituted the new UnitTestMain.cpp (the preprocessed file) for the original one. After that I could set a breakpoint in framework_impl::register_test_unit(). What I see is that the test case being registered is the "this" pointer from an object that was created with new, so it looks like the error is a bug in Snow Leopard. That's about all I know right now. I have never used boost unit test, so don't really know how to put together a reduced test case that can be submitted to Apple. Any takers? :-) - Rush This seems to be once again this bug in Boost.Test:
http://www.nabble.com/-Boost.Test--valgrind-complains-about-invalid-reads-td...
http://www.nabble.com/-Boost.Test--Error:-Non-aligned-pointer-being-freed-td...
Try making the test_unit destructor virtual and your problem should be resolved.
Thank you, Peter. That does resolve the problem.
Do you have any idea whether 1.40 still has this problem?
Yes, 1.40.0 also suffers from this bug.
Maybe we can finally convince Gennadiy to fix this issue in SVN.
This would stop forcing people to use their own patches each time a new version of Boost is released.
+1
I reported this before too. *everyone* (on 64bit?) is seeing this, and the fix is trivial.
Now I have gone back and read the original thread about valgrind complaints. I see that Gennadiy is rather adamant about not changing the code. However, under Snow Leopard the deletion of test cases fails completely and aborts the program. The C-style cast in framework_impl::clear() does not work under Snow Leopard, but it does work correctly if test_unit has a virtual destructor. I suspect that the noise level over this is going to increase rapidly. - Rush