shell32: Fix handle leak on consecutive Init() calls.

This commit is contained in:
Nikolay Sivov 2013-09-09 11:35:37 +04:00 committed by Alexandre Julliard
parent 891cf2ac54
commit f0d17b5c17
2 changed files with 37 additions and 2 deletions

View File

@ -184,6 +184,10 @@ static HRESULT WINAPI IQueryAssociations_fnInit(
FIXME("hwnd != NULL not supported\n");
if (cfFlags != 0)
FIXME("unsupported flags: %x\n", cfFlags);
RegCloseKey(This->hkeySource);
RegCloseKey(This->hkeyProgID);
This->hkeySource = This->hkeyProgID = NULL;
if (pszAssoc != NULL)
{
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT,
@ -191,8 +195,8 @@ static HRESULT WINAPI IQueryAssociations_fnInit(
0,
KEY_READ,
&This->hkeySource);
if (ret != ERROR_SUCCESS)
return E_FAIL;
if (ret)
return S_OK;
/* if this is not a prog id */
if ((*pszAssoc == '.') || (*pszAssoc == '{'))
{
@ -468,6 +472,9 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
if (!pcchOut)
return E_UNEXPECTED;
if (!This->hkeySource && !This->hkeyProgID)
return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION);
switch (str)
{
case ASSOCSTR_COMMAND:

View File

@ -103,6 +103,8 @@ struct assoc_getstring_test
};
static const WCHAR httpW[] = {'h','t','t','p',0};
static const WCHAR httpsW[] = {'h','t','t','p','s',0};
static const WCHAR badW[] = {'b','a','d','b','a','d',0};
static struct assoc_getstring_test getstring_tests[] =
{
@ -163,6 +165,31 @@ static void test_IQueryAssociations_GetString(void)
IQueryAssociations_Release(assoc);
}
static void test_IQueryAssociations_Init(void)
{
IQueryAssociations *assoc;
HRESULT hr;
DWORD len;
hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&assoc);
ok(hr == S_OK, "failed to create object, 0x%x\n", hr);
hr = IQueryAssociations_Init(assoc, 0, NULL, NULL, NULL);
ok(hr == E_INVALIDARG, "Init failed, 0x%08x\n", hr);
hr = IQueryAssociations_Init(assoc, 0, httpW, NULL, NULL);
ok(hr == S_OK, "Init failed, 0x%08x\n", hr);
hr = IQueryAssociations_Init(assoc, 0, badW, NULL, NULL);
ok(hr == S_OK || broken(hr == S_FALSE) /* pre-vista */, "Init failed, 0x%08x\n", hr);
len = 0;
hr = IQueryAssociations_GetString(assoc, 0, ASSOCSTR_EXECUTABLE, NULL, NULL, &len);
ok(hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) || broken(hr == E_FAIL) /* pre-vista */, "got 0x%08x\n", hr);
IQueryAssociations_Release(assoc);
}
START_TEST(assoc)
{
IQueryAssociations *qa;
@ -176,6 +203,7 @@ START_TEST(assoc)
{
test_IQueryAssociations_QueryInterface();
test_IQueryAssociations_GetString();
test_IQueryAssociations_Init();
IQueryAssociations_Release(qa);
}