]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Argh. With DEBUG and MALLOC_LOG enabled, I found output intended for the
authorJacob Nevins <jacobn@chiark.greenend.org.uk>
Sun, 8 Dec 2002 14:44:42 +0000 (14:44 +0000)
committerJacob Nevins <jacobn@chiark.greenend.org.uk>
Sun, 8 Dec 2002 14:44:42 +0000 (14:44 +0000)
console was ending up in one or other of debug.log or putty_mem.log. I
don't really understand why, but I've put some extra paranoia and caching
in debug(()) and that seems to have fixed it (tm). Perhaps I can get back
to debugging...

[originally from svn r2291]

misc.c

diff --git a/misc.c b/misc.c
index 6b2f9e68a08c7e94e4683b353575d64920977be7..496d30e3b786d1af99da808a4138d066aa33acc2 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -592,6 +592,7 @@ void safefree(void *ptr)
 
 #ifdef DEBUG
 static FILE *debug_fp = NULL;
+static HANDLE debug_hdl = INVALID_HANDLE_VALUE;
 static int debug_got_console = 0;
 
 static void dputs(char *buf)
@@ -599,15 +600,18 @@ static void dputs(char *buf)
     DWORD dw;
 
     if (!debug_got_console) {
-       AllocConsole();
-       debug_got_console = 1;
+       if (AllocConsole()) {
+           debug_got_console = 1;
+           debug_hdl = GetStdHandle(STD_OUTPUT_HANDLE);
+       }
     }
     if (!debug_fp) {
        debug_fp = fopen("debug.log", "w");
     }
 
-    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw,
-             NULL);
+    if (debug_hdl != INVALID_HANDLE_VALUE) {
+       WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL);
+    }
     fputs(buf, debug_fp);
     fflush(debug_fp);
 }