Re: [Boost-bugs] [Boost C++ Libraries] #5582: There is a memory leak in the BOOST_AUTO_TEST_CASE_TEMPLATE

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5582: There is a memory leak in the BOOST_AUTO_TEST_CASE_TEMPLATE
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-08-16 07:55:54


#5582: There is a memory leak in the BOOST_AUTO_TEST_CASE_TEMPLATE
------------------------------------------------------+---------------------
  Reporter: Anton Matosov <anton.matosov@…> | Owner: rogeeff
      Type: Bugs | Status: new
 Milestone: Boost 1.47.0 | Component: test
   Version: Boost 1.46.1 | Severity: Problem
Resolution: | Keywords: test unit_test memory leak
------------------------------------------------------+---------------------

Comment (by Anton Matosov <anton.matosov@…>):

 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 :)

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5582#comment:2>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC