reg: Use a helper function to resize a memory buffer.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2017-08-01 12:31:09 +00:00 committed by Alexandre Julliard
parent a1bc33ae5c
commit e7ea8380e0
1 changed files with 21 additions and 3 deletions

View File

@ -90,6 +90,24 @@ static void *heap_xalloc(size_t size)
return buf; return buf;
} }
static void *heap_xrealloc(void *buf, size_t size)
{
void *new_buf;
if (buf)
new_buf = HeapReAlloc(GetProcessHeap(), 0, buf, size);
else
new_buf = HeapAlloc(GetProcessHeap(), 0, size);
if (!new_buf)
{
ERR("Out of memory!\n");
exit(1);
}
return new_buf;
}
static BOOL heap_free(void *buf) static BOOL heap_free(void *buf)
{ {
return HeapFree(GetProcessHeap(), 0, buf); return HeapFree(GetProcessHeap(), 0, buf);
@ -662,7 +680,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
if (rc == ERROR_MORE_DATA) if (rc == ERROR_MORE_DATA)
{ {
max_data_bytes = data_size; max_data_bytes = data_size;
data = HeapReAlloc(GetProcessHeap(), 0, data, max_data_bytes); data = heap_xrealloc(data, max_data_bytes);
} }
else break; else break;
} }
@ -754,12 +772,12 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
if (data_size > max_data_bytes) if (data_size > max_data_bytes)
{ {
max_data_bytes = data_size; max_data_bytes = data_size;
data = HeapReAlloc(GetProcessHeap(), 0, data, max_data_bytes); data = heap_xrealloc(data, max_data_bytes);
} }
else else
{ {
max_value_len *= 2; max_value_len *= 2;
value_name = HeapReAlloc(GetProcessHeap(), 0, value_name, max_value_len * sizeof(WCHAR)); value_name = heap_xrealloc(value_name, max_value_len * sizeof(WCHAR));
} }
} }
else break; else break;