Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Test] workaround for reported memory leaks when using MFC?
From: Andrew Durward (andrew.durward_at_[hidden])
Date: 2009-04-13 17:51:15


Hi,
I'm trying to use Boost.Test (dynamic variant) in a dll that also uses MFC.
I'm using the console_test_runner application found in libs/test/tools to
load my dll. My compiler is MSVC v8 and my OS is Windows Vista.

Unfortunately, when the MFC dll gets unloaded prior to shutdown it invokes
the CRT's memory leak detection routine which falsely reports that any
memory allocated by the (yet to be unloaded) unit test framework has been
leaked. Obviously, the problem here is with MFC and searching the 'net will
yield numerous complaints on the topic.

One such search turned up a promising workaround [1] that involves
installing a custom report handler to "swallow" the extraneous memory leak
reports. However it appears this approach is defeated by Boost.Test
installing its own report handler when no debugger is present.

Can anybody suggest a different workaround? The problem effectively renders
Boost.Test unusable in this configuration when MFC is present.

Here is sample code to reproduce the problem:

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#define _AFXDLL
#include <afx.h>

BOOST_AUTO_TEST_CASE( test_case )
{
        BOOST_CHECK( true );
}

extern "C"
{

__declspec( dllexport )
bool init_unit_test()
{
        return true;
}

}

Build this into a dll and load it with the --test argument of
console_test_runner. You should see:
  Detected memory leaks!
  Dumping objects ->
followed by numerous blocks of "leaked" memory.

Thanks for any help,
andrew

[1] "Why does MFC call _CrtDumpMemoryLeaks ?!?" in microsoft.public.vc.mfc
http://tinyurl.com/ddas7u


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net