
Gennadiy Rozental wrote:
Peter Klotz wrote:
James Sutherland wrote:
Try compiling a debug version. That will give you line numbers to help you track it down easier. James
Found the problem. It was a non virtual destructor in class test_unit.
Since test_unit is the base class of test_case, test_suite and master_test_suite_t it needs a virtual destructor.
No. It does not. We never delete test units through pointer to test_unit.
In deregister_test_unit() a test_unit* pointer is passed which may actually point to a derived class. Calling delete without a virtual destructor leads to undefined behavior (and makes valgrind complain).
deregister_test_unit does not cause delete command. In fact it's being call from destructor.
Please see the output of my simple example (with extra output in Boost.Test): With virtual destructor in test_unit: register_test_unit( test_case* tc ) tc=0x42c4ab0 register_test_unit( test_suite* ts ) ts=0x42c4ba8 Running 1 test case... *** No errors detected deregister_test_unit( test_unit* tu ) tu=0x42c4ba8 deregister_test_unit( test_unit* tu ) tu=0x42c4ab0 Here the pointers in register_test_unit()/deregister_test_unit() match as expected. Without virtual destructor in test_unit:register_test_unit( test_case* tc ) register_test_unit( test_case* tc ) tc=0x42c4ab0 register_test_unit( test_suite* ts ) ts=0x42c4ba8 Running 1 test case... *** No errors detected deregister_test_unit( test_unit* tu ) tu=0x42c4bac deregister_test_unit( test_unit* tu ) tu=0x42c4ab0 Here the test_unit pointer is not correct and does not match the one initially registered! I agree that deregister_test_unit() does not delete the test_suite but the pointers ought to match. Maybe you can run my simple test case using valgrind. I used version 3.3.1 under Ubuntu 8.10 i386 (gcc 4.3.2) and Red Hat Enterprise Linux 5 x86_64 (gcc 4.1.2). Regards, Peter.