advapi32/registry: Use heap helpers.

This commit is contained in:
Nikolay Sivov 2014-08-28 17:42:22 +04:00 committed by Alexandre Julliard
parent 33627f02aa
commit ad012a8a57

View file

@ -35,6 +35,7 @@
#include "winerror.h" #include "winerror.h"
#include "winternl.h" #include "winternl.h"
#include "winuser.h" #include "winuser.h"
#include "advapi32_misc.h"
#include "wine/unicode.h" #include "wine/unicode.h"
#include "wine/debug.h" #include "wine/debug.h"
@ -647,8 +648,8 @@ LSTATUS WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_
while (status == STATUS_BUFFER_OVERFLOW) while (status == STATUS_BUFFER_OVERFLOW)
{ {
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_NODE_INFORMATION *)buf_ptr; info = (KEY_NODE_INFORMATION *)buf_ptr;
status = NtEnumerateKey( hkey, index, KeyNodeInformation, status = NtEnumerateKey( hkey, index, KeyNodeInformation,
@ -681,7 +682,7 @@ LSTATUS WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_
} }
} }
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
return RtlNtStatusToDosError( status ); return RtlNtStatusToDosError( status );
} }
@ -711,8 +712,8 @@ LSTATUS WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_l
while (status == STATUS_BUFFER_OVERFLOW) while (status == STATUS_BUFFER_OVERFLOW)
{ {
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_NODE_INFORMATION *)buf_ptr; info = (KEY_NODE_INFORMATION *)buf_ptr;
status = NtEnumerateKey( hkey, index, KeyNodeInformation, status = NtEnumerateKey( hkey, index, KeyNodeInformation,
@ -749,7 +750,7 @@ LSTATUS WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_l
} }
} }
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
return RtlNtStatusToDosError( status ); return RtlNtStatusToDosError( status );
} }
@ -840,8 +841,8 @@ LSTATUS WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPD
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW) while (status == STATUS_BUFFER_OVERFLOW)
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_FULL_INFORMATION *)buf_ptr; info = (KEY_FULL_INFORMATION *)buf_ptr;
status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size ); status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
@ -871,7 +872,7 @@ LSTATUS WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPD
if (modif) *modif = *(FILETIME *)&info->LastWriteTime; if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
return RtlNtStatusToDosError( status ); return RtlNtStatusToDosError( status );
} }
@ -1026,8 +1027,8 @@ LSTATUS WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDW
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW) while (status == STATUS_BUFFER_OVERFLOW)
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_FULL_INFORMATION *)buf_ptr; info = (KEY_FULL_INFORMATION *)buf_ptr;
status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size ); status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
@ -1059,7 +1060,7 @@ LSTATUS WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDW
if (modif) *modif = *(FILETIME *)&info->LastWriteTime; if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
return RtlNtStatusToDosError( status ); return RtlNtStatusToDosError( status );
} }
@ -1253,7 +1254,7 @@ LSTATUS WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD typ
{ {
DWORD lenW; DWORD lenW;
RtlMultiByteToUnicodeSize( &lenW, (const char *)data, count ); RtlMultiByteToUnicodeSize( &lenW, (const char *)data, count );
if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY; if (!(dataW = heap_alloc( lenW ))) return ERROR_OUTOFMEMORY;
RtlMultiByteToUnicodeN( dataW, lenW, NULL, (const char *)data, count ); RtlMultiByteToUnicodeN( dataW, lenW, NULL, (const char *)data, count );
count = lenW; count = lenW;
data = (BYTE *)dataW; data = (BYTE *)dataW;
@ -1265,7 +1266,7 @@ LSTATUS WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD typ
status = NtSetValueKey( hkey, &nameW, 0, type, data, count ); status = NtSetValueKey( hkey, &nameW, 0, type, data, count );
RtlFreeUnicodeString( &nameW ); RtlFreeUnicodeString( &nameW );
} }
HeapFree( GetProcessHeap(), 0, dataW ); heap_free( dataW );
return RtlNtStatusToDosError( status ); return RtlNtStatusToDosError( status );
} }
@ -1391,8 +1392,8 @@ LSTATUS WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDW
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count) while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count)
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr; info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation, status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
@ -1418,7 +1419,7 @@ LSTATUS WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDW
if (count) *count = total_size - info_size; if (count) *count = total_size - info_size;
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
return RtlNtStatusToDosError(status); return RtlNtStatusToDosError(status);
} }
@ -1484,8 +1485,8 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW) while (status == STATUS_BUFFER_OVERFLOW)
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
{ {
status = STATUS_NO_MEMORY; status = STATUS_NO_MEMORY;
goto done; goto done;
@ -1529,7 +1530,7 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO
if (count) *count = total_size - info_size; if (count) *count = total_size - info_size;
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
RtlFreeUnicodeString( &nameW ); RtlFreeUnicodeString( &nameW );
return RtlNtStatusToDosError(status); return RtlNtStatusToDosError(status);
} }
@ -1711,9 +1712,9 @@ LSTATUS WINAPI RegGetValueW( HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue,
dwType == REG_EXPAND_SZ && !(dwFlags & RRF_NOEXPAND)) dwType == REG_EXPAND_SZ && !(dwFlags & RRF_NOEXPAND))
{ {
do { do {
HeapFree(GetProcessHeap(), 0, pvBuf); heap_free(pvBuf);
pvBuf = HeapAlloc(GetProcessHeap(), 0, cbData); pvBuf = heap_alloc(cbData);
if (!pvBuf) if (!pvBuf)
{ {
ret = ERROR_NOT_ENOUGH_MEMORY; ret = ERROR_NOT_ENOUGH_MEMORY;
@ -1751,7 +1752,7 @@ LSTATUS WINAPI RegGetValueW( HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue,
CopyMemory(pvData, pvBuf, *pcbData); CopyMemory(pvData, pvBuf, *pcbData);
} }
HeapFree(GetProcessHeap(), 0, pvBuf); heap_free(pvBuf);
} }
if (pszSubKey && pszSubKey[0]) if (pszSubKey && pszSubKey[0])
@ -1807,9 +1808,9 @@ LSTATUS WINAPI RegGetValueA( HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue,
dwType == REG_EXPAND_SZ && !(dwFlags & RRF_NOEXPAND)) dwType == REG_EXPAND_SZ && !(dwFlags & RRF_NOEXPAND))
{ {
do { do {
HeapFree(GetProcessHeap(), 0, pvBuf); heap_free(pvBuf);
pvBuf = HeapAlloc(GetProcessHeap(), 0, cbData); pvBuf = heap_alloc(cbData);
if (!pvBuf) if (!pvBuf)
{ {
ret = ERROR_NOT_ENOUGH_MEMORY; ret = ERROR_NOT_ENOUGH_MEMORY;
@ -1847,7 +1848,7 @@ LSTATUS WINAPI RegGetValueA( HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue,
CopyMemory(pvData, pvBuf, *pcbData); CopyMemory(pvData, pvBuf, *pcbData);
} }
HeapFree(GetProcessHeap(), 0, pvBuf); heap_free(pvBuf);
} }
if (pszSubKey && pszSubKey[0]) if (pszSubKey && pszSubKey[0])
@ -1914,8 +1915,8 @@ LSTATUS WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW) while (status == STATUS_BUFFER_OVERFLOW)
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr; info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation, status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
@ -1960,7 +1961,7 @@ LSTATUS WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_
if (count) *count = info->DataLength; if (count) *count = info->DataLength;
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
return RtlNtStatusToDosError(status); return RtlNtStatusToDosError(status);
} }
@ -2001,8 +2002,8 @@ LSTATUS WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_c
/* retry with a dynamically allocated buffer */ /* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW) while (status == STATUS_BUFFER_OVERFLOW)
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = heap_alloc( total_size )))
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr; info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation, status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
@ -2065,7 +2066,7 @@ LSTATUS WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_c
if (count) *count = info->DataLength; if (count) *count = info->DataLength;
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) heap_free( buf_ptr );
return RtlNtStatusToDosError(status); return RtlNtStatusToDosError(status);
} }
@ -2776,7 +2777,7 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
result = ERROR_FILE_NOT_FOUND; result = ERROR_FILE_NOT_FOUND;
goto cleanup; goto cleanup;
} }
pwszTempBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); pwszTempBuffer = heap_alloc(cbData);
if (!pwszTempBuffer) { if (!pwszTempBuffer) {
result = ERROR_NOT_ENOUGH_MEMORY; result = ERROR_NOT_ENOUGH_MEMORY;
goto cleanup; goto cleanup;
@ -2788,14 +2789,14 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
if (dwValueType == REG_EXPAND_SZ) { if (dwValueType == REG_EXPAND_SZ) {
cbData = ExpandEnvironmentStringsW(pwszTempBuffer, NULL, 0) * sizeof(WCHAR); cbData = ExpandEnvironmentStringsW(pwszTempBuffer, NULL, 0) * sizeof(WCHAR);
if (!cbData) goto cleanup; if (!cbData) goto cleanup;
pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); pwszExpandedBuffer = heap_alloc(cbData);
if (!pwszExpandedBuffer) { if (!pwszExpandedBuffer) {
result = ERROR_NOT_ENOUGH_MEMORY; result = ERROR_NOT_ENOUGH_MEMORY;
goto cleanup; goto cleanup;
} }
ExpandEnvironmentStringsW(pwszTempBuffer, pwszExpandedBuffer, cbData); ExpandEnvironmentStringsW(pwszTempBuffer, pwszExpandedBuffer, cbData);
} else { } else {
pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); pwszExpandedBuffer = heap_alloc(cbData);
memcpy(pwszExpandedBuffer, pwszTempBuffer, cbData); memcpy(pwszExpandedBuffer, pwszTempBuffer, cbData);
} }
@ -2825,8 +2826,8 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
} }
cleanup: cleanup:
HeapFree(GetProcessHeap(), 0, pwszTempBuffer); heap_free(pwszTempBuffer);
HeapFree(GetProcessHeap(), 0, pwszExpandedBuffer); heap_free(pwszExpandedBuffer);
return result; return result;
} }
@ -2846,7 +2847,7 @@ LSTATUS WINAPI RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, LPSTR pszBuffer, DW
valueW.Buffer = baseDirW.Buffer = pwszBuffer = NULL; valueW.Buffer = baseDirW.Buffer = pwszBuffer = NULL;
if (!RtlCreateUnicodeStringFromAsciiz(&valueW, pszValue) || if (!RtlCreateUnicodeStringFromAsciiz(&valueW, pszValue) ||
!RtlCreateUnicodeStringFromAsciiz(&baseDirW, pszBaseDir) || !RtlCreateUnicodeStringFromAsciiz(&baseDirW, pszBaseDir) ||
!(pwszBuffer = HeapAlloc(GetProcessHeap(), 0, cbData))) !(pwszBuffer = heap_alloc(cbData)))
{ {
result = ERROR_NOT_ENOUGH_MEMORY; result = ERROR_NOT_ENOUGH_MEMORY;
goto cleanup; goto cleanup;
@ -2862,7 +2863,7 @@ LSTATUS WINAPI RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, LPSTR pszBuffer, DW
} }
cleanup: cleanup:
HeapFree(GetProcessHeap(), 0, pwszBuffer); heap_free(pwszBuffer);
RtlFreeUnicodeString(&baseDirW); RtlFreeUnicodeString(&baseDirW);
RtlFreeUnicodeString(&valueW); RtlFreeUnicodeString(&valueW);
@ -2931,7 +2932,7 @@ LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR)) if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
{ {
/* Name too big: alloc a buffer for it */ /* Name too big: alloc a buffer for it */
if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR)))) if (!(lpszName = heap_alloc( dwMaxLen*sizeof(WCHAR))))
{ {
ret = ERROR_NOT_ENOUGH_MEMORY; ret = ERROR_NOT_ENOUGH_MEMORY;
goto cleanup; goto cleanup;
@ -2966,7 +2967,7 @@ LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
cleanup: cleanup:
/* Free buffer if allocated */ /* Free buffer if allocated */
if (lpszName != szNameBuf) if (lpszName != szNameBuf)
HeapFree( GetProcessHeap(), 0, lpszName); heap_free( lpszName);
if(lpszSubKey) if(lpszSubKey)
RegCloseKey(hSubKey); RegCloseKey(hSubKey);
return ret; return ret;