From 3e2788210950e816cdb905bc32b9e414aa45742c Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sun, 17 Sep 2017 16:27:17 +0200 Subject: [PATCH] Issue #597 - Add WIN CRT memory debug in tidy.c --- console/tidy.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index bc5b4e8..281ca3c 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -27,6 +27,10 @@ #endif #if !defined(NDEBUG) && defined(_MSC_VER) #include "sprtf.h" +#ifdef _CRTDBG_MAP_ALLOC +#include +#include +#endif #endif #ifndef SPRTF @@ -1882,7 +1886,7 @@ int main( int argc, char** argv ) { ctmbstr prog = argv[0]; ctmbstr cfgfil = NULL, errfil = NULL, htmlfil = NULL; - TidyDoc tdoc = tidyCreate(); + TidyDoc tdoc = NULL; int status = 0; tmbstr locale = NULL; @@ -1890,6 +1894,16 @@ int main( int argc, char** argv ) uint contentWarnings = 0; uint accessWarnings = 0; +#if !defined(NDEBUG) && defined(_MSC_VER) +#if defined(_CRTDBG_MAP_ALLOC) + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + set_log_file((char *)"temptidy.txt", 0); + /* add_append_log(1); */ +#endif + + tdoc = tidyCreate(); + tidySetMessageCallback( tdoc, reportCallback); /* experimental group */ errout = stderr; /* initialize to stderr */ @@ -1914,12 +1928,6 @@ int main( int argc, char** argv ) SetConsoleOutputCP(CP_UTF8); #endif - -#if !defined(NDEBUG) && defined(_MSC_VER) - set_log_file((char *)"temptidy.txt", 0); - /* add_append_log(1); */ -#endif - /* * Look for default configuration files using any of * the following possibilities: