From f0d17b5c171c8814851f740280e103681bce0c22 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 9 Sep 2013 11:35:37 +0400 Subject: [PATCH] shell32: Fix handle leak on consecutive Init() calls. --- dlls/shell32/assoc.c | 11 +++++++++-- dlls/shell32/tests/assoc.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dlls/shell32/assoc.c b/dlls/shell32/assoc.c index 77b0a2dcd9a..848bf879b3c 100644 --- a/dlls/shell32/assoc.c +++ b/dlls/shell32/assoc.c @@ -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: diff --git a/dlls/shell32/tests/assoc.c b/dlls/shell32/tests/assoc.c index abfe6d4b556..ff999e98dc7 100644 --- a/dlls/shell32/tests/assoc.c +++ b/dlls/shell32/tests/assoc.c @@ -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); }