regedit: Fix potential buffer leak, simplify error handling (Coverity).

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2015-12-22 00:55:00 +03:00 committed by Alexandre Julliard
parent 0aa56cabe4
commit c9fb3b7f8f

View file

@ -95,17 +95,17 @@ static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pKe
LPWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
{
int pathLen = 0, maxLen;
int pathLen = 0, maxLen = 1024;
WCHAR *pathBuffer;
pathBuffer = HeapAlloc(GetProcessHeap(), 0, 1024*sizeof(WCHAR));
if (!hItem) {
hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0);
if (!hItem) return NULL;
}
pathBuffer = HeapAlloc(GetProcessHeap(), 0, maxLen*sizeof(WCHAR));
if (!pathBuffer) return NULL;
*pathBuffer = 0;
maxLen = HeapSize(GetProcessHeap(), 0, pathBuffer);
if (maxLen == (SIZE_T) - 1) return NULL;
maxLen = maxLen / sizeof(WCHAR);
if (!hItem) hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0);
if (!hItem) return NULL;
if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL;
return pathBuffer;
}