Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Detecting memory leaks in BOOST test cases.

Detecting memory leaks in BOOST test cases.

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shailesh H
    wrote on last edited by
    #1

    Hi All, I have a BOOST test case as below BOOST_AUTO_TEST_CASE( BoostUnitTestSample ) { // seven ways to detect and report the same error: BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error somefunction_whichleaksmemory();----------->memory leak function. if( add( 2,2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error } I want to programmatically detect the memory leak in function somefunction_whichleaks() and get information like line number and filename where the leaked occurred. And most importantly I should know in which test case this leaked occured.May be I would like to have a dump of all this information in some file. Does anybody knows a solution to this?

    J 1 Reply Last reply
    0
    • S Shailesh H

      Hi All, I have a BOOST test case as below BOOST_AUTO_TEST_CASE( BoostUnitTestSample ) { // seven ways to detect and report the same error: BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error somefunction_whichleaksmemory();----------->memory leak function. if( add( 2,2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error } I want to programmatically detect the memory leak in function somefunction_whichleaks() and get information like line number and filename where the leaked occurred. And most importantly I should know in which test case this leaked occured.May be I would like to have a dump of all this information in some file. Does anybody knows a solution to this?

      J Offline
      J Offline
      JackDingler
      wrote on last edited by
      #2

      If you're using MFC, add this snippet above your code:

      #ifdef _DEBUG
      #undef THIS_FILE
      static char THIS_FILE[]=__FILE__;
      #define new DEBUG_NEW
      #endif

      Your memory leaks will then appear in the output window. Note that it doesn't work correctly with overloaded new constructors, so for those you may need some $ifdef guards.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups