shlwapi: Fix some memory, handle and reference count leaks in RegisterDefaultAcceptHeaders.

This commit is contained in:
Nikolay Sivov 2010-03-27 02:53:02 +03:00 committed by Alexandre Julliard
parent 5ca6d9b5be
commit 076676d448
1 changed files with 36 additions and 27 deletions

View File

@ -309,24 +309,22 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
BSTR property; BSTR property;
IEnumFORMATETC* pIEnumFormatEtc = NULL; IEnumFORMATETC* pIEnumFormatEtc = NULL;
VARIANTARG var; VARIANTARG var;
HRESULT hRet; HRESULT hr;
IWebBrowserApp* pBrowser = NULL; IWebBrowserApp* pBrowser;
TRACE("(%p, %p)\n", lpBC, lpUnknown); TRACE("(%p, %p)\n", lpBC, lpUnknown);
/* Get An IWebBrowserApp interface from lpUnknown */ hr = IUnknown_QueryService(lpUnknown, &IID_IWebBrowserApp, &IID_IWebBrowserApp, (void**)&pBrowser);
hRet = IUnknown_QueryService(lpUnknown, &IID_IWebBrowserApp, &IID_IWebBrowserApp, (PVOID)&pBrowser); if (FAILED(hr))
if (FAILED(hRet) || !pBrowser) return hr;
return E_NOINTERFACE;
V_VT(&var) = VT_EMPTY; V_VT(&var) = VT_EMPTY;
/* The property we get is the browsers clipboard enumerator */ /* The property we get is the browsers clipboard enumerator */
property = SysAllocString(szProperty); property = SysAllocString(szProperty);
hRet = IWebBrowserApp_GetProperty(pBrowser, property, &var); hr = IWebBrowserApp_GetProperty(pBrowser, property, &var);
SysFreeString(property); SysFreeString(property);
if (FAILED(hRet)) if (FAILED(hr)) goto exit;
return hRet;
if (V_VT(&var) == VT_EMPTY) if (V_VT(&var) == VT_EMPTY)
{ {
@ -340,7 +338,10 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Current" if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Current"
"Version\\Internet Settings\\Accepted Documents", &hDocs)) "Version\\Internet Settings\\Accepted Documents", &hDocs))
return E_FAIL; {
hr = E_FAIL;
goto exit;
}
/* Get count of values in key */ /* Get count of values in key */
while (!dwRet) while (!dwRet)
@ -355,7 +356,11 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
/* Note: dwCount = number of items + 1; The extra item is the end node */ /* Note: dwCount = number of items + 1; The extra item is the end node */
format = formatList = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(FORMATETC)); format = formatList = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(FORMATETC));
if (!formatList) if (!formatList)
return E_OUTOFMEMORY; {
RegCloseKey(hDocs);
hr = E_OUTOFMEMORY;
goto exit;
}
if (dwNumValues > 1) if (dwNumValues > 1)
{ {
@ -372,7 +377,12 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
dwRet = RegEnumValueA(hDocs, dwCount, szKeyBuff, &dwKeySize, 0, &dwType, dwRet = RegEnumValueA(hDocs, dwCount, szKeyBuff, &dwKeySize, 0, &dwType,
(PBYTE)szValueBuff, &dwValueSize); (PBYTE)szValueBuff, &dwValueSize);
if (!dwRet) if (!dwRet)
return E_FAIL; {
HeapFree(GetProcessHeap(), 0, formatList);
RegCloseKey(hDocs);
hr = E_FAIL;
goto exit;
}
format->cfFormat = RegisterClipboardFormatA(szValueBuff); format->cfFormat = RegisterClipboardFormatA(szValueBuff);
format->ptd = NULL; format->ptd = NULL;
@ -385,6 +395,8 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
} }
} }
RegCloseKey(hDocs);
/* Terminate the (maybe empty) list, last entry has a cfFormat of 0 */ /* Terminate the (maybe empty) list, last entry has a cfFormat of 0 */
format->cfFormat = 0; format->cfFormat = 0;
format->ptd = NULL; format->ptd = NULL;
@ -393,22 +405,21 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
format->tymed = -1; format->tymed = -1;
/* Create a clipboard enumerator */ /* Create a clipboard enumerator */
hRet = CreateFormatEnumerator(dwNumValues, formatList, &pIEnumFormatEtc); hr = CreateFormatEnumerator(dwNumValues, formatList, &pIEnumFormatEtc);
HeapFree(GetProcessHeap(), 0, formatList);
if (FAILED(hRet) || !pIEnumFormatEtc) if (FAILED(hr)) goto exit;
return hRet;
/* Set our enumerator as the browsers property */ /* Set our enumerator as the browsers property */
V_VT(&var) = VT_UNKNOWN; V_VT(&var) = VT_UNKNOWN;
V_UNKNOWN(&var) = (IUnknown*)pIEnumFormatEtc; V_UNKNOWN(&var) = (IUnknown*)pIEnumFormatEtc;
property = SysAllocString(szProperty); property = SysAllocString(szProperty);
hRet = IWebBrowserApp_PutProperty(pBrowser, property, var); hr = IWebBrowserApp_PutProperty(pBrowser, property, var);
SysFreeString(property); SysFreeString(property);
if (FAILED(hRet)) if (FAILED(hr))
{ {
IEnumFORMATETC_Release(pIEnumFormatEtc); IEnumFORMATETC_Release(pIEnumFormatEtc);
goto RegisterDefaultAcceptHeaders_Exit; goto exit;
} }
} }
@ -422,28 +433,26 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
/* Get an IEnumFormatEtc interface from the variants value */ /* Get an IEnumFormatEtc interface from the variants value */
pIEnumFormatEtc = NULL; pIEnumFormatEtc = NULL;
hRet = IUnknown_QueryInterface(pIUnknown, &IID_IEnumFORMATETC, hr = IUnknown_QueryInterface(pIUnknown, &IID_IEnumFORMATETC, (void**)&pIEnumFormatEtc);
(PVOID)&pIEnumFormatEtc); if (hr == S_OK && pIEnumFormatEtc)
if (hRet == S_OK && pIEnumFormatEtc)
{ {
/* Clone and register the enumerator */ /* Clone and register the enumerator */
hRet = IEnumFORMATETC_Clone(pIEnumFormatEtc, &pClone); hr = IEnumFORMATETC_Clone(pIEnumFormatEtc, &pClone);
if (hRet == S_OK && pClone) if (hr == S_OK && pClone)
{ {
RegisterFormatEnumerator(lpBC, pClone, 0); RegisterFormatEnumerator(lpBC, pClone, 0);
IEnumFORMATETC_Release(pClone); IEnumFORMATETC_Release(pClone);
} }
/* Release the IEnumFormatEtc interface */
IEnumFORMATETC_Release(pIUnknown); IEnumFORMATETC_Release(pIUnknown);
} }
IUnknown_Release(V_UNKNOWN(&var)); IUnknown_Release(V_UNKNOWN(&var));
} }
RegisterDefaultAcceptHeaders_Exit: exit:
IWebBrowserApp_Release(pBrowser); IWebBrowserApp_Release(pBrowser);
return hRet; return hr;
} }
/************************************************************************* /*************************************************************************