Commit 674ef559 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

winedbg: Do proper error management when reallocating memory.

parent c40bccb8
......@@ -202,6 +202,7 @@ BOOL break_add_break(const ADDRESS64* addr, BOOL verbose, BOOL swbp)
*/
BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue, BOOL swbp)
{
struct dbg_delayed_bp* new;
ADDRESS64 addr;
types_extract_as_address(lvalue, &addr);
......@@ -215,13 +216,15 @@ BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue, BOOL swbp)
return FALSE;
}
dbg_printf("Unable to add breakpoint, will check again any time a new DLL is loaded\n");
dbg_curr_process->delayed_bp =
dbg_heap_realloc(dbg_curr_process->delayed_bp,
sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = FALSE;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.addr = addr;
new = dbg_heap_realloc(dbg_curr_process->delayed_bp,
sizeof(struct dbg_delayed_bp) * (dbg_curr_process->num_delayed_bp + 1));
if (!new) return FALSE;
dbg_curr_process->delayed_bp = new;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp].is_symbol = FALSE;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp].software_bp = swbp;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp].u.addr = addr;
dbg_curr_process->num_delayed_bp++;
return TRUE;
}
return FALSE;
......@@ -234,6 +237,7 @@ BOOL break_add_break_from_lvalue(const struct dbg_lvalue* lvalue, BOOL swbp)
*/
void break_add_break_from_id(const char *name, int lineno, BOOL swbp)
{
struct dbg_delayed_bp* new;
struct dbg_lvalue lvalue;
int i;
......@@ -256,13 +260,15 @@ void break_add_break_from_id(const char *name, int lineno, BOOL swbp)
lineno == dbg_curr_process->delayed_bp[i].u.symbol.lineno)
return;
}
dbg_curr_process->delayed_bp = dbg_heap_realloc(dbg_curr_process->delayed_bp,
sizeof(struct dbg_delayed_bp) * ++dbg_curr_process->num_delayed_bp);
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].is_symbol = TRUE;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].software_bp = swbp;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp - 1].u.symbol.lineno = lineno;
new = dbg_heap_realloc(dbg_curr_process->delayed_bp,
sizeof(struct dbg_delayed_bp) * (dbg_curr_process->num_delayed_bp + 1));
if (!new) return;
dbg_curr_process->delayed_bp = new;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp].is_symbol = TRUE;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp].software_bp = swbp;
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp].u.symbol.name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1), name);
dbg_curr_process->delayed_bp[dbg_curr_process->num_delayed_bp].u.symbol.lineno = lineno;
dbg_curr_process->num_delayed_bp++;
}
struct cb_break_lineno
......
......@@ -514,8 +514,14 @@ static int input_fetch_entire_line(const char* pfx, char** line)
if (len + 2 > alloc)
{
char* new;
while (len + 2 > alloc) alloc *= 2;
buffer = dbg_heap_realloc(buffer, alloc);
if (!(new = dbg_heap_realloc(buffer, alloc)))
{
HeapFree(GetProcessHeap(), 0, buffer);
return -1;
}
buffer = new;
}
buffer[len++] = ch;
}
......
......@@ -63,10 +63,13 @@ BOOL display_add(struct expr *exp, int count, char format)
if (i == maxdisplays)
{
struct display *new;
/* no space left - expand */
new = dbg_heap_realloc(displaypoints,
(maxdisplays + DISPTAB_DELTA) * sizeof(*displaypoints));
if (!new) return FALSE;
displaypoints = new;
maxdisplays += DISPTAB_DELTA;
displaypoints = dbg_heap_realloc(displaypoints,
maxdisplays * sizeof(*displaypoints));
}
if (i == ndisplays) ndisplays++;
......
......@@ -199,8 +199,10 @@ static BOOL CALLBACK info_mod_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
if (im->num_used + 1 > im->num_alloc)
{
struct info_module* new = dbg_heap_realloc(im->modules, (im->num_alloc + 16) * sizeof(*im->modules));
if (!new) return FALSE; /* stop enumeration in case of OOM */
im->num_alloc += 16;
im->modules = dbg_heap_realloc(im->modules, im->num_alloc * sizeof(*im->modules));
im->modules = new;
}
im->modules[im->num_used].mi.SizeOfStruct = sizeof(im->modules[im->num_used].mi);
if (SymGetModuleInfo64(dbg_curr_process->handle, base, &im->modules[im->num_used].mi))
......@@ -315,8 +317,10 @@ static void class_walker(HWND hWnd, struct class_walker* cw)
{
if (cw->used >= cw->alloc)
{
ATOM* new = dbg_heap_realloc(cw->table, (cw->alloc + 16) * sizeof(ATOM));
if (!new) return;
cw->alloc += 16;
cw->table = dbg_heap_realloc(cw->table, cw->alloc * sizeof(ATOM));
cw->table = new;
}
cw->table[cw->used++] = atom;
info_win32_class(hWnd, clsName);
......@@ -547,8 +551,15 @@ void info_win32_processes(void)
dp.entries[dp.count++].children = -1;
if (dp.count >= dp.alloc)
{
dp.entries = HeapReAlloc(GetProcessHeap(), 0, dp.entries, sizeof(*dp.entries) * (dp.alloc *= 2));
if (!dp.entries) return;
struct dump_proc_entry* new = HeapReAlloc(GetProcessHeap(), 0, dp.entries, sizeof(*dp.entries) * (dp.alloc * 2));
if (!new)
{
CloseHandle(snap);
HeapFree(GetProcessHeap(), 0, dp.entries);
return;
}
dp.alloc *= 2;
dp.entries = new;
}
dp.entries[dp.count].proc.dwSize = sizeof(dp.entries[dp.count].proc);
ok = Process32Next(snap, &dp.entries[dp.count].proc);
......
......@@ -204,8 +204,10 @@ unsigned stack_fetch_frames(const dbg_ctx_t* _ctx)
SymFunctionTableAccess64, SymGetModuleBase64, NULL, SYM_STKWALK_DEFAULT)) ||
nf == 0) /* we always register first frame information */
{
dbg_curr_thread->frames = dbg_heap_realloc(dbg_curr_thread->frames,
(nf + 1) * sizeof(dbg_curr_thread->frames[0]));
struct dbg_frame* new = dbg_heap_realloc(dbg_curr_thread->frames,
(nf + 1) * sizeof(dbg_curr_thread->frames[0]));
if (!new) break;
dbg_curr_thread->frames = new;
dbg_curr_thread->frames[nf].addr_pc = sf.AddrPC;
dbg_curr_thread->frames[nf].linear_pc = (DWORD_PTR)memory_to_linear_addr(&sf.AddrPC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment