Andrew Nguyen : winedbg: Eliminate a possible memory leak in input_fetch_entire_line.

Alexandre Julliard julliard at winehq.org
Wed May 18 11:15:35 CDT 2011


Module: wine
Branch: master
Commit: 218d970bddc398a07da31631e31f7314c5ca1cf9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=218d970bddc398a07da31631e31f7314c5ca1cf9

Author: Andrew Nguyen <anguyen at codeweavers.com>
Date:   Wed May 18 07:09:21 2011 -0500

winedbg: Eliminate a possible memory leak in input_fetch_entire_line.

---

 programs/winedbg/dbg.y |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/programs/winedbg/dbg.y b/programs/winedbg/dbg.y
index 4f2da25..fa5e9a7 100644
--- a/programs/winedbg/dbg.y
+++ b/programs/winedbg/dbg.y
@@ -462,42 +462,39 @@ static HANDLE dbg_parser_output;
 
 int      input_fetch_entire_line(const char* pfx, char** line)
 {
+    char*       buffer;
     char        ch;
     DWORD	nread;
     size_t      len, alloc;
-    
+
     /* as of today, console handles can be file handles... so better use file APIs rather than
      * console's
      */
     WriteFile(dbg_parser_output, pfx, strlen(pfx), &nread, NULL);
 
-    if (*line)
-    {
-        alloc = HeapSize(GetProcessHeap(), 0, *line);
-        assert(alloc);
-    }
-    else
-    {
-        *line = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
-        assert(*line);
-    }
+    buffer = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
+    assert(buffer != NULL);
 
     len = 0;
     do
     {
         if (!ReadFile(dbg_parser_input, &ch, 1, &nread, NULL) || nread == 0)
+        {
+            HeapFree(GetProcessHeap(), 0, buffer);
             return -1;
+        }
 
         if (len + 2 > alloc)
         {
             while (len + 2 > alloc) alloc *= 2;
-            *line = dbg_heap_realloc(*line, alloc);
+            buffer = dbg_heap_realloc(buffer, alloc);
         }
-        (*line)[len++] = ch;
+        buffer[len++] = ch;
     }
     while (ch != '\n');
-    (*line)[len] = '\0';
+    buffer[len] = '\0';
 
+    *line = buffer;
     return len;
 }
 




More information about the wine-cvs mailing list