catch_leak_detector.cpp 924 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Created by Martin on 12/07/2017.
  3. *
  4. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include "catch_leak_detector.h"
  8. #include "catch_interfaces_registry_hub.h"
  9. #ifdef CATCH_CONFIG_WINDOWS_CRTDBG
  10. #include <crtdbg.h>
  11. namespace Catch {
  12. LeakDetector::LeakDetector() {
  13. int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  14. flag |= _CRTDBG_LEAK_CHECK_DF;
  15. flag |= _CRTDBG_ALLOC_MEM_DF;
  16. _CrtSetDbgFlag(flag);
  17. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  18. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  19. // Change this to leaking allocation's number to break there
  20. _CrtSetBreakAlloc(-1);
  21. }
  22. }
  23. #else
  24. Catch::LeakDetector::LeakDetector() {}
  25. #endif
  26. Catch::LeakDetector::~LeakDetector() {
  27. Catch::cleanUp();
  28. }