advapi32/registry: Use heap helpers.
This commit is contained in:
parent
33627f02aa
commit
ad012a8a57
|
@ -35,6 +35,7 @@
|
|||
#include "winerror.h"
|
||||
#include "winternl.h"
|
||||
#include "winuser.h"
|
||||
#include "advapi32_misc.h"
|
||||
|
||||
#include "wine/unicode.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)
|
||||
{
|
||||
/* retry with a dynamically allocated buffer */
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
info = (KEY_NODE_INFORMATION *)buf_ptr;
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -711,8 +712,8 @@ LSTATUS WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_l
|
|||
while (status == STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
/* retry with a dynamically allocated buffer */
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
info = (KEY_NODE_INFORMATION *)buf_ptr;
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -840,8 +841,8 @@ LSTATUS WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPD
|
|||
/* retry with a dynamically allocated buffer */
|
||||
while (status == STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
info = (KEY_FULL_INFORMATION *)buf_ptr;
|
||||
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;
|
||||
|
||||
done:
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
return RtlNtStatusToDosError( status );
|
||||
}
|
||||
|
||||
|
@ -1026,8 +1027,8 @@ LSTATUS WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDW
|
|||
/* retry with a dynamically allocated buffer */
|
||||
while (status == STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
info = (KEY_FULL_INFORMATION *)buf_ptr;
|
||||
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;
|
||||
|
||||
done:
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
return RtlNtStatusToDosError( status );
|
||||
}
|
||||
|
||||
|
@ -1253,7 +1254,7 @@ LSTATUS WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD typ
|
|||
{
|
||||
DWORD lenW;
|
||||
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 );
|
||||
count = lenW;
|
||||
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 );
|
||||
RtlFreeUnicodeString( &nameW );
|
||||
}
|
||||
HeapFree( GetProcessHeap(), 0, dataW );
|
||||
heap_free( dataW );
|
||||
return RtlNtStatusToDosError( status );
|
||||
}
|
||||
|
||||
|
@ -1391,8 +1392,8 @@ LSTATUS WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDW
|
|||
/* retry with a dynamically allocated buffer */
|
||||
while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count)
|
||||
{
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
|
||||
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;
|
||||
|
||||
done:
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
return RtlNtStatusToDosError(status);
|
||||
}
|
||||
|
||||
|
@ -1484,8 +1485,8 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO
|
|||
/* retry with a dynamically allocated buffer */
|
||||
while (status == STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
{
|
||||
status = STATUS_NO_MEMORY;
|
||||
goto done;
|
||||
|
@ -1529,7 +1530,7 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO
|
|||
if (count) *count = total_size - info_size;
|
||||
|
||||
done:
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
RtlFreeUnicodeString( &nameW );
|
||||
return RtlNtStatusToDosError(status);
|
||||
}
|
||||
|
@ -1711,9 +1712,9 @@ LSTATUS WINAPI RegGetValueW( HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue,
|
|||
dwType == REG_EXPAND_SZ && !(dwFlags & RRF_NOEXPAND))
|
||||
{
|
||||
do {
|
||||
HeapFree(GetProcessHeap(), 0, pvBuf);
|
||||
heap_free(pvBuf);
|
||||
|
||||
pvBuf = HeapAlloc(GetProcessHeap(), 0, cbData);
|
||||
pvBuf = heap_alloc(cbData);
|
||||
if (!pvBuf)
|
||||
{
|
||||
ret = ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
@ -1751,7 +1752,7 @@ LSTATUS WINAPI RegGetValueW( HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue,
|
|||
CopyMemory(pvData, pvBuf, *pcbData);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pvBuf);
|
||||
heap_free(pvBuf);
|
||||
}
|
||||
|
||||
if (pszSubKey && pszSubKey[0])
|
||||
|
@ -1807,9 +1808,9 @@ LSTATUS WINAPI RegGetValueA( HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue,
|
|||
dwType == REG_EXPAND_SZ && !(dwFlags & RRF_NOEXPAND))
|
||||
{
|
||||
do {
|
||||
HeapFree(GetProcessHeap(), 0, pvBuf);
|
||||
heap_free(pvBuf);
|
||||
|
||||
pvBuf = HeapAlloc(GetProcessHeap(), 0, cbData);
|
||||
pvBuf = heap_alloc(cbData);
|
||||
if (!pvBuf)
|
||||
{
|
||||
ret = ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
@ -1847,7 +1848,7 @@ LSTATUS WINAPI RegGetValueA( HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue,
|
|||
CopyMemory(pvData, pvBuf, *pcbData);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pvBuf);
|
||||
heap_free(pvBuf);
|
||||
}
|
||||
|
||||
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 */
|
||||
while (status == STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
|
||||
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;
|
||||
|
||||
done:
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
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 */
|
||||
while (status == STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
if (!(buf_ptr = heap_alloc( total_size )))
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
|
||||
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;
|
||||
|
||||
done:
|
||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||
if (buf_ptr != buffer) heap_free( buf_ptr );
|
||||
return RtlNtStatusToDosError(status);
|
||||
}
|
||||
|
||||
|
@ -2776,7 +2777,7 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
|
|||
result = ERROR_FILE_NOT_FOUND;
|
||||
goto cleanup;
|
||||
}
|
||||
pwszTempBuffer = HeapAlloc(GetProcessHeap(), 0, cbData);
|
||||
pwszTempBuffer = heap_alloc(cbData);
|
||||
if (!pwszTempBuffer) {
|
||||
result = ERROR_NOT_ENOUGH_MEMORY;
|
||||
goto cleanup;
|
||||
|
@ -2788,14 +2789,14 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
|
|||
if (dwValueType == REG_EXPAND_SZ) {
|
||||
cbData = ExpandEnvironmentStringsW(pwszTempBuffer, NULL, 0) * sizeof(WCHAR);
|
||||
if (!cbData) goto cleanup;
|
||||
pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData);
|
||||
pwszExpandedBuffer = heap_alloc(cbData);
|
||||
if (!pwszExpandedBuffer) {
|
||||
result = ERROR_NOT_ENOUGH_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
ExpandEnvironmentStringsW(pwszTempBuffer, pwszExpandedBuffer, cbData);
|
||||
} else {
|
||||
pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData);
|
||||
pwszExpandedBuffer = heap_alloc(cbData);
|
||||
memcpy(pwszExpandedBuffer, pwszTempBuffer, cbData);
|
||||
}
|
||||
|
||||
|
@ -2825,8 +2826,8 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
|
|||
}
|
||||
|
||||
cleanup:
|
||||
HeapFree(GetProcessHeap(), 0, pwszTempBuffer);
|
||||
HeapFree(GetProcessHeap(), 0, pwszExpandedBuffer);
|
||||
heap_free(pwszTempBuffer);
|
||||
heap_free(pwszExpandedBuffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2846,7 +2847,7 @@ LSTATUS WINAPI RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, LPSTR pszBuffer, DW
|
|||
valueW.Buffer = baseDirW.Buffer = pwszBuffer = NULL;
|
||||
if (!RtlCreateUnicodeStringFromAsciiz(&valueW, pszValue) ||
|
||||
!RtlCreateUnicodeStringFromAsciiz(&baseDirW, pszBaseDir) ||
|
||||
!(pwszBuffer = HeapAlloc(GetProcessHeap(), 0, cbData)))
|
||||
!(pwszBuffer = heap_alloc(cbData)))
|
||||
{
|
||||
result = ERROR_NOT_ENOUGH_MEMORY;
|
||||
goto cleanup;
|
||||
|
@ -2862,7 +2863,7 @@ LSTATUS WINAPI RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, LPSTR pszBuffer, DW
|
|||
}
|
||||
|
||||
cleanup:
|
||||
HeapFree(GetProcessHeap(), 0, pwszBuffer);
|
||||
heap_free(pwszBuffer);
|
||||
RtlFreeUnicodeString(&baseDirW);
|
||||
RtlFreeUnicodeString(&valueW);
|
||||
|
||||
|
@ -2931,7 +2932,7 @@ LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
|
|||
if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
|
||||
{
|
||||
/* 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;
|
||||
goto cleanup;
|
||||
|
@ -2966,7 +2967,7 @@ LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
|
|||
cleanup:
|
||||
/* Free buffer if allocated */
|
||||
if (lpszName != szNameBuf)
|
||||
HeapFree( GetProcessHeap(), 0, lpszName);
|
||||
heap_free( lpszName);
|
||||
if(lpszSubKey)
|
||||
RegCloseKey(hSubKey);
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue