Memory leak detection with boost :: test

I am trying 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 installing the define preprocessor

_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 determine main using BOOST_TEST_NO_MAIN, and reset myself as follows:

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

But without success. How can I do that?

+6
source share
3 answers

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

+5
source

In MSVC, you can set a breakpoint on distribution number 1466, in code:

  _crtBreakAlloc = 1466 

or in the Clock window, you can add _crtBreakAlloc and a value of 1466 after starting the application (of course, you need a breakpoint in the main function). MSDN Details

+4
source

Try using a debugger! For example, using deleteaker, you can select a stack to see where the memory was allocated.

0
source

Source: https://habr.com/ru/post/897882/


All Articles