[PATCH 5/8] regedit: Use the heap_*() functions in edit.c where possible
Hugh McMaster
hugh.mcmaster at outlook.com
Thu Jul 27 07:25:26 CDT 2017
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/regedit/edit.c | 44 +++++++++++++++++++-------------------------
programs/regedit/regproc.c | 2 +-
programs/regedit/regproc.h | 1 +
3 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c
index 038a37aff8..6733968389 100644
--- a/programs/regedit/edit.c
+++ b/programs/regedit/edit.c
@@ -122,12 +122,11 @@ static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
case IDOK:
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
len = GetWindowTextLengthW(hwndValue);
- if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(WCHAR)))) {
- stringValueData = valueData;
- if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
- *stringValueData = 0;
+ valueData = heap_xrealloc(stringValueData, (len + 1) * sizeof(WCHAR));
+ stringValueData = valueData;
+ if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
+ *stringValueData = 0;
}
- }
/* Fall through */
case IDCANCEL:
EndDialog(hwndDlg, wParam);
@@ -159,13 +158,13 @@ static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wPara
case IDOK:
params = (struct edit_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
cbData = SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, 0, 0);
- pData = HeapAlloc(GetProcessHeap(), 0, cbData);
+ pData = heap_xalloc(cbData);
if (pData)
{
SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)cbData, (LPARAM)pData);
lRet = RegSetValueExW(params->hKey, params->lpszValueName, 0, REG_BINARY, pData, cbData);
- HeapFree(GetProcessHeap(), 0, pData);
+ heap_free(pData);
}
else
lRet = ERROR_OUTOFMEMORY;
@@ -206,7 +205,7 @@ static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType,
if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
if (len) *len = 1;
if (lpType) *lpType = REG_SZ;
- buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
+ buffer = heap_xalloc(sizeof(WCHAR));
*buffer = '\0';
return buffer;
}
@@ -214,10 +213,7 @@ static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType,
goto done;
}
if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
- if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen+sizeof(WCHAR)))) {
- error_code_messagebox(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
- goto done;
- }
+ buffer = heap_xalloc(valueDataLen + sizeof(WCHAR));
lRet = RegQueryValueExW(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
if (lRet != ERROR_SUCCESS) {
error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
@@ -229,7 +225,7 @@ static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType,
return buffer;
done:
- HeapFree(GetProcessHeap(), 0, buffer);
+ heap_free(buffer);
return NULL;
}
@@ -307,7 +303,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
if (lRet == ERROR_SUCCESS) result = TRUE;
else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
}
- HeapFree(GetProcessHeap(), 0, valueA);
+ heap_free(valueA);
}
} else if ( type == REG_BINARY ) {
struct edit_params params;
@@ -325,8 +321,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
for ( i = 0, count = 0; i < len - 1; i++)
if ( !stringValueData[i] && stringValueData[i + 1] )
count++;
- tmpValueData = HeapAlloc( GetProcessHeap(), 0, ( len + count ) * sizeof(WCHAR));
- if ( !tmpValueData ) goto done;
+ tmpValueData = heap_xalloc((len + count) * sizeof(WCHAR));
for ( i = 0, j = 0; i < len - 1; i++)
{
@@ -339,15 +334,14 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
tmpValueData[j++] = stringValueData[i];
}
tmpValueData[j] = stringValueData[i];
- HeapFree( GetProcessHeap(), 0, stringValueData);
+ heap_free(stringValueData);
stringValueData = tmpValueData;
tmpValueData = NULL;
if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK)
{
len = lstrlenW( stringValueData );
- tmpValueData = HeapAlloc( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
- if ( !tmpValueData ) goto done;
+ tmpValueData = heap_xalloc((len + 2) * sizeof(WCHAR));
for ( i = 0, j = 0; i < len - 1; i++)
{
@@ -363,7 +357,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
tmpValueData[j++] = stringValueData[i];
tmpValueData[j++] = 0;
tmpValueData[j++] = 0;
- HeapFree( GetProcessHeap(), 0, stringValueData);
+ heap_free(stringValueData);
stringValueData = tmpValueData;
lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(WCHAR));
@@ -379,13 +373,13 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
{
int index = SendMessageW(g_pChildWnd->hListWnd, LVM_GETNEXTITEM, -1,
MAKELPARAM(LVNI_FOCUSED | LVNI_SELECTED, 0));
- HeapFree(GetProcessHeap(), 0, stringValueData);
+ heap_free(stringValueData);
stringValueData = read_value(hwnd, hKey, valueName, &type, &len);
format_value_data(g_pChildWnd->hListWnd, index, type, stringValueData, len);
}
done:
- HeapFree(GetProcessHeap(), 0, stringValueData);
+ heap_free(stringValueData);
stringValueData = NULL;
RegCloseKey(hKey);
return result;
@@ -535,7 +529,7 @@ BOOL RenameValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR oldName, LPC
result = TRUE;
done:
- HeapFree(GetProcessHeap(), 0, value);
+ heap_free(value);
RegCloseKey(hKey);
return result;
}
@@ -559,7 +553,7 @@ BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR newName)
} else {
LPWSTR srcSubKey_copy;
- parentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(keyPath)+1)*sizeof(WCHAR));
+ parentPath = heap_xalloc((lstrlenW(keyPath) + 1) * sizeof(WCHAR));
lstrcpyW(parentPath, keyPath);
srcSubKey_copy = strrchrW(parentPath, '\\');
*srcSubKey_copy = 0;
@@ -604,7 +598,7 @@ done:
RegCloseKey(destKey);
if (parentKey) {
RegCloseKey(parentKey);
- HeapFree(GetProcessHeap(), 0, parentPath);
+ heap_free(parentPath);
}
return result;
}
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index aae7738ae6..3f055b6f51 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -55,7 +55,7 @@ void *heap_xalloc(size_t size)
return buf;
}
-static void *heap_xrealloc(void *buf, size_t size)
+void *heap_xrealloc(void *buf, size_t size)
{
void *new_buf;
diff --git a/programs/regedit/regproc.h b/programs/regedit/regproc.h
index a0ed438fd1..469e988f23 100644
--- a/programs/regedit/regproc.h
+++ b/programs/regedit/regproc.h
@@ -38,6 +38,7 @@ void __cdecl error_exit(unsigned int id, ...);
char *GetMultiByteString(const WCHAR *strW);
void *heap_xalloc(size_t size);
+void *heap_xrealloc(void *buf, size_t size);
BOOL heap_free(void *buf);
BOOL import_registry_file(FILE *reg_file);
void delete_registry_key(WCHAR *reg_key_name);
--
2.13.2
More information about the wine-patches
mailing list