mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 12:54:13 +00:00
winedbg: Eliminate a possible memory leak in input_fetch_entire_line.
This commit is contained in:
parent
9981938486
commit
218d970bdd
1 changed files with 11 additions and 14 deletions
|
@ -462,42 +462,39 @@ static HANDLE dbg_parser_output;
|
||||||
|
|
||||||
int input_fetch_entire_line(const char* pfx, char** line)
|
int input_fetch_entire_line(const char* pfx, char** line)
|
||||||
{
|
{
|
||||||
|
char* buffer;
|
||||||
char ch;
|
char ch;
|
||||||
DWORD nread;
|
DWORD nread;
|
||||||
size_t len, alloc;
|
size_t len, alloc;
|
||||||
|
|
||||||
/* as of today, console handles can be file handles... so better use file APIs rather than
|
/* as of today, console handles can be file handles... so better use file APIs rather than
|
||||||
* console's
|
* console's
|
||||||
*/
|
*/
|
||||||
WriteFile(dbg_parser_output, pfx, strlen(pfx), &nread, NULL);
|
WriteFile(dbg_parser_output, pfx, strlen(pfx), &nread, NULL);
|
||||||
|
|
||||||
if (*line)
|
buffer = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
|
||||||
{
|
assert(buffer != NULL);
|
||||||
alloc = HeapSize(GetProcessHeap(), 0, *line);
|
|
||||||
assert(alloc);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*line = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
|
|
||||||
assert(*line);
|
|
||||||
}
|
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!ReadFile(dbg_parser_input, &ch, 1, &nread, NULL) || nread == 0)
|
if (!ReadFile(dbg_parser_input, &ch, 1, &nread, NULL) || nread == 0)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, buffer);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (len + 2 > alloc)
|
if (len + 2 > alloc)
|
||||||
{
|
{
|
||||||
while (len + 2 > alloc) alloc *= 2;
|
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');
|
while (ch != '\n');
|
||||||
(*line)[len] = '\0';
|
buffer[len] = '\0';
|
||||||
|
|
||||||
|
*line = buffer;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue