From e7ea8380e038cb8507a1b065f7372e4ea4ac7fa9 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Tue, 1 Aug 2017 12:31:09 +0000 Subject: [PATCH] reg: Use a helper function to resize a memory buffer. Signed-off-by: Hugh McMaster Signed-off-by: Alexandre Julliard --- programs/reg/reg.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 953f5d39484..c086763afe8 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -90,6 +90,24 @@ static void *heap_xalloc(size_t size) 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) { 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) { max_data_bytes = data_size; - data = HeapReAlloc(GetProcessHeap(), 0, data, max_data_bytes); + data = heap_xrealloc(data, max_data_bytes); } else break; } @@ -754,12 +772,12 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse) if (data_size > max_data_bytes) { max_data_bytes = data_size; - data = HeapReAlloc(GetProcessHeap(), 0, data, max_data_bytes); + data = heap_xrealloc(data, max_data_bytes); } else { 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;