Search code examples
c++memory-leaksboost-test

Memory leak detection with boost::test


I try to enable msvc memory leak detection with line number like this snippet I found here:

Detected memory leaks!
Dumping objects ->
C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) : {18} 
normal block at 0x00780E80, 64 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.

I tried to set the preprocessor define

_CRTDBG_MAP_ALLOC

manually in the project properties but I only get this:

Dumping objects ->
{1466} normal block at 0x00BD4DD0, 40 bytes long.
 Data: <(o;   ; (o;   1 > 28 6F 3B 00 90 A9 3B 00 28 6F 3B 00 00 D6 31 10

without line numbers. I also tried to manually define main by using BOOST_TEST_NO_MAIN and dump by myself like this:

int main( int argc, char* argv[] )
{
    int res = ::boost::unit_test::unit_test_main( &init_function, argc, argv );  
    _CrtDumpMemoryLeaks();
    return res;
}

But also without any success. How can this be done?


Solution

  • Using Boost.Test you can use --detect_memory_leaks="allocation number"