From 2287a5348733207122f19558f46deabffe2291a0 Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Sun, 15 Jan 2006 23:17:57 +0000 Subject: [PATCH] add memory leak detection git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@475 7ec92016-0320-0410-acc4-a06ded1c099a --- test/Pimpl/main.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/Pimpl/main.cpp b/test/Pimpl/main.cpp index ae65e68..78f7eb8 100755 --- a/test/Pimpl/main.cpp +++ b/test/Pimpl/main.cpp @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // The Loki Library -// Copyright (c) 2006 Peter Kmmel +// Copyright (c) 2006 Peter Kümmel // Permission to use, copy, modify, distribute and sell this software for any // purpose is hereby granted without fee, provided that the above copyright // notice appear in all copies and that both that copyright notice and this @@ -136,8 +136,42 @@ void D::foo() ///////////////////////////////////////// void test_more(); +//#define MSVC_DETECT_MEMORY_LEAKS +#ifdef MSVC_DETECT_MEMORY_LEAKS + +#include +#include + +void heap_debug() +{ + int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); + + // Turn on leak-checking bit + tmpFlag |= _CRTDBG_LEAK_CHECK_DF; + + //tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF; + + // Turn off CRT block checking bit + tmpFlag &= ~_CRTDBG_CHECK_CRT_DF; + + // Set flag to the new value + _CrtSetDbgFlag( tmpFlag ); + +} + +#else + +void heap_debug() +{ +} + +#endif + + + int main() { + heap_debug(); A* a = new A; B* b = new B;