#5582 closed Bugs (fixed)
There is a memory leak in the BOOST_AUTO_TEST_CASE_TEMPLATE
Reported by: | Owned by: | Gennadiy Rozental | |
---|---|---|---|
Milestone: | Boost 1.59.0 | Component: | test |
Version: | Boost 1.46.1 | Severity: | Problem |
Keywords: | test unit_test memory leak | Cc: |
Description
There is memory leak in the boost::unit_test::ut_detail::generate_test_case_4_type::operator() which is used by boost::unit_test::ut_detail::template_test_case_gen which in its turn is used by BOOST_AUTO_TEST_CASE_TEMPLATE
The problematic code is provided below. The test_case created here never gets deleted.
template<typename TestType> void operator()( mpl::identity<TestType> ) { ... m_holder.m_test_cases.push_back( new test_case( full_name, test_case_template_invoker<TestCaseTemplate,TestType>() ) ); }
Below is the code that can be used to reproduce the issue:
#define BOOST_TEST_MAIN #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> #include <boost/test/test_case_template.hpp> #include <boost/mpl/list.hpp> BOOST_AUTO_TEST_SUITE( TestMemLeak ) BOOST_AUTO_TEST_CASE_TEMPLATE( TestCase, Type, boost::mpl::list<int> ) { } BOOST_AUTO_TEST_SUITE_END()
Note: This leak is detected only when application is linked with C runtime statically. Configured test application can be found in the attachment
Execution output:
Running 1 test case... *** No errors detected Detected memory leaks! Dumping objects -> {103} normal block at 0x00808D50, 4 bytes long. Data: <int > 69 6E 74 00 {102} normal block at 0x00808D18, 8 bytes long. Data: <P > 50 8D 80 00 00 00 00 00 Object dump complete.
Attachments (1)
Change History (5)
by , 11 years ago
Attachment: | BoostTestMemoryLeak.zip added |
---|
comment:1 by , 11 years ago
Any status change on this? If there is a workaround that I can put in place to alleviate this problem before it is put in a release, that would be great.
comment:2 by , 11 years ago
It seems that issue is not in boost test library, but with memory leaks detection itself. The leak detected is a memory allocated for type_info (typeid) but not yet freed.
Here is the MSDN page related to the issue: http://connect.microsoft.com/VisualStudio/feedback/details/106937/memory-leaks-reported-by-debug-crt-inside-typeinfo-name
Here is the smallest code that reproduces the "leak":
#include <crtdbg.h> #include <typeinfo> // for typeid int main() { _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); _CrtSetDbgFlag(_CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF); typeid(int).name(); return 0; }
The good news here is that there is a workaround for this issue provided on the MSDN page specified above. Minimum code that worked in my case is:
void free_typeinfo_memory() { __type_info_node *pNode = __type_info_root_node.next; __type_info_node *tmpNode = &__type_info_root_node; for( ; pNode!=NULL; pNode = tmpNode ) { tmpNode = pNode->next; delete pNode->memPtr; delete pNode; } }
I have placed the call to free_typeinfo_memory() at the very last line of the main() and leaks didn't come up again :)
comment:3 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 7 years ago
Milestone: | Boost 1.47.0 → Boost 1.59.0 |
---|
Configured VS2008 test application which reproduces the memory leak in boost::test library