Permalink
Browse files

Merge branch 'dev-windows-leakdetection'

  • Loading branch information...
2 parents 90b3946 + 30e4dbe commit 8cd413572a5223f14c88aacd2539e2d4e2e3acc3 @horenmar horenmar committed Feb 17, 2017
Showing with 17 additions and 0 deletions.
  1. +3 −0 docs/configuration.md
  2. +14 −0 include/internal/catch_default_main.hpp
@@ -76,13 +76,16 @@ All C++11 support can be disabled with `CATCH_CONFIG_NO_CPP11`
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (extremely minor) features for compilation speed
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
+ CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
At this moment, `CATCH_CONFIG_FAST_COMPILE` changes only the behaviour of the `-b` (`--break`) flag, making it break into debugger in a stack frame *below* the actual test, unlike the default behaviour, where the break into debugger occurs in the same stack frame as the actual test. `CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined, in all translation units that are linked into single test binary, or the behaviour of setting `-b` flag will be unpredictable.
`CATCH_CONFIG_POSIX_SIGNALS` is on by default, except when Catch is compiled under `Cygwin`, where it is disabled by default (but can be force-enabled by defining `CATCH_CONFIG_POSIX_SIGNALS`).
+`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running. _Note that this instrumentation is only done when Catch supplies its own main._
+
Just as with the C++11 conformance toggles, these toggles can be disabled by using `_NO_` form of the toggle, e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
# Windows header clutter
@@ -10,8 +10,22 @@
#ifndef __OBJC__
+#ifdef CATCH_CONFIG_WINDOWS_CRTDBG
+#include <crtdbg.h>
+#endif
+
// Standard C/C++ main entry point
int main (int argc, char * argv[]) {
+#ifdef CATCH_CONFIG_WINDOWS_CRTDBG
+ int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
+ flag |= _CRTDBG_LEAK_CHECK_DF;
+ flag |= _CRTDBG_ALLOC_MEM_DF;
+ _CrtSetDbgFlag(flag);
+ _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+ _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
+ // Change this to leaking allocation's number to break there
+ _CrtSetBreakAlloc(-1);
+#endif
int result = Catch::Session().run( argc, argv );
return ( result < 0xff ? result : 0xff );
}

0 comments on commit 8cd4135

Please sign in to comment.