toeb / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Consider adding memory leak checking #125

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Attached is a file using the Win32 API's _CrtMemCheckpoint and 
_CrtMemDifference functions in a test fixture's SetUp and TearDown methods 
to check for memory leaks during a test.

With #define WIN32 and #define _DEBUG, any heap allocations that are not 
freed by the end of a test are reported on stderr, and cause a test 
failure. This works great, except for two issues:

1) _CrtMemDifference includes lots of heap allocated memory from the test 
framework--there ends up being lots of noise around the actual leak.

To solve I need a way to call _CrtMemCheckpoint *immediately* before and 
after the test case is run, without any google test allocations happening 
in between. Am I missing an obvious way to do this?

2) Inside TearDown I check Test::HasFatalFailure() to make sure we don't 
report leaks when there is already a failure. But when an EXPECT_XXX has 
failed, it's not a fatal failure, and the leak finder finds unfreed heap 
allocations which are not actually test leaks--it's more google test stuff. 

This is partially caused by #1 -- so if that issue is solved, then I don't 
think it will matter.

Any help is appreciated!

Original issue reported on code.google.com by kevinwat...@gmail.com on 5 Mar 2009 at 6:02

Attachments:

GoogleCodeExporter commented 9 years ago
Could you please post this on googletestframework@googlegroups.com instead?  We 
use
that for discussions and Q&As.  The discussion on the public forum will help us
decide whether we should create an issue for it.  Thanks.

Original comment by zhanyong...@gmail.com on 30 Mar 2009 at 11:52