winegdb: Fix crash in empty first command

Vitor T. Sessak vitor.sessak at m4x.org
Tue Mar 7 14:06:49 CST 2006


2006/3/7, Eric Pouech
>
>2006/3/6, Vitor T. Sessak <vitor.sessak at m4x.org <http://www.winehq.org/mailman/listinfo/wine-patches>>:
>>/
/>>/ Changelog:
/>>/ winegdb: Fix crash in empty first command
/>>/
/>>/ Winedbg crashes when pressing enter as its first command.
/>
>
>this is wrong as the last_line will be HeapFree'd when the next command is
>keyed in.

You are right. I've changed it and fixed the FIXME too.

diff --git a/programs/winedbg/debug.l b/programs/winedbg/debug.l
index 71d10f0..13ad5ce 100644
--- a/programs/winedbg/debug.l
+++ b/programs/winedbg/debug.l
@@ -34,27 +34,31 @@
 static int read_input(const char* pfx, char* buf, int size)
 {
     size_t      len;
-static char*  last_line = NULL;
-static size_t last_line_idx = 0;
+    static char*  last_line = NULL;
+    static char*  this_line = NULL;
+    static size_t last_line_idx = 0;
+
+    if (last_line == NULL)
+    {
+        last_line = HeapAlloc(GetProcessHeap(), 0, 16);
+        this_line = HeapAlloc(GetProcessHeap(), 0, 16);
+        last_line[0] = '\n';
+        last_line[1] = 0;
+    }	
 
     /* try first to fetch the remaining of an existing line */
     if (last_line_idx == 0)
     {
-        char* tmp = NULL;
         /* no remaining chars to be read from last line, grab a brand new line up to '\n' */
         lexeme_flush();
-        len = input_fetch_entire_line(pfx, &tmp);
-        /* FIXME: should have a pair of buffers, and switch between the two, instead of
-         * reallocating a new one for each line
-         */
-        if (len == 0 || (len == 1 && tmp[0] == '\n') || (len == 2 && tmp[0] == '\r' && tmp[1] == '\n'))
-        {
-            HeapFree(GetProcessHeap(), 0, tmp);
-        }
-        else
+        len = input_fetch_entire_line(pfx, &this_line);
+
+        if (!(len == 0 || (len == 1 && this_line[0] == '\n') || (len == 2 && this_line[0] == '\r' && this_line[1] == '\n')))
         {
-            HeapFree(GetProcessHeap(), 0, last_line);
-            last_line = tmp;
+            char* tmp;
+            tmp = last_line;
+            last_line = this_line;
+            this_line = tmp;
         }
     }
 





More information about the wine-patches mailing list