Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 922
schoetbi Avatar asked Sep 23 '11 06:09

schoetbi


2 Answers

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

like image 102
Gennadiy Rozental Avatar answered Oct 18 '22 22:10

Gennadiy Rozental


In MSVC you can set a breakpoint to the allocation number 1466, in the code:

  _crtBreakAlloc = 1466

or in the Watch window you can add _crtBreakAlloc and value 1466 once the application started (of course you need a breakpoint in the main function). More details on MSDN

like image 34
onof Avatar answered Oct 19 '22 00:10

onof