Hugh McMaster : reg: Use a helper function to resize a memory buffer.
Alexandre Julliard
julliard at winehq.org
Tue Aug 1 16:43:15 CDT 2017
Module: wine
Branch: master
Commit: e7ea8380e038cb8507a1b065f7372e4ea4ac7fa9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e7ea8380e038cb8507a1b065f7372e4ea4ac7fa9
Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date: Tue Aug 1 12:31:09 2017 +0000
reg: Use a helper function to resize a memory buffer.
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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 953f5d3..c086763 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;
More information about the wine-cvs
mailing list