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 8 #include "catch_leak_detector.h" 9 #include "catch_interfaces_registry_hub.h" 10 11 12 #ifdef CATCH_CONFIG_WINDOWS_CRTDBG 13 #include <crtdbg.h> 14 15 namespace Catch { 16 LeakDetector()17 LeakDetector::LeakDetector() { 18 int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); 19 flag |= _CRTDBG_LEAK_CHECK_DF; 20 flag |= _CRTDBG_ALLOC_MEM_DF; 21 _CrtSetDbgFlag(flag); 22 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 23 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); 24 // Change this to leaking allocation's number to break there 25 _CrtSetBreakAlloc(-1); 26 } 27 } 28 29 #else 30 LeakDetector()31 Catch::LeakDetector::LeakDetector() {} 32 33 #endif 34 ~LeakDetector()35Catch::LeakDetector::~LeakDetector() { 36 Catch::cleanUp(); 37 } 38