[PATCH 2/2] shell32: fix memory leaks in tests and avoid closing the caller's key

Theodore Dubois tblodt at icloud.com
Sun Jun 5 11:35:39 CDT 2016


Signed-off-by: Theodore Dubois <tblodt at icloud.com>
---
 dlls/shell32/assoc.c       |  4 +++-
 dlls/shell32/tests/assoc.c | 11 +++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/dlls/shell32/assoc.c b/dlls/shell32/assoc.c
index a3d21b9..1ccf0e2 100644
--- a/dlls/shell32/assoc.c
+++ b/dlls/shell32/assoc.c
@@ -259,7 +259,9 @@ static HRESULT WINAPI IQueryAssociations_fnInit(
     }
     else if (hkeyProgid != NULL)
     {
-        This->hkeySource = This->hkeyProgID = hkeyProgid;
+        /* reopen the key so we don't end up closing a key owned by the caller */
+        RegOpenKeyExW(hkeyProgid, NULL, 0, KEY_READ, &This->hkeyProgID);
+        This->hkeySource = This->hkeyProgID;
         return S_OK;
     }
     else
diff --git a/dlls/shell32/tests/assoc.c b/dlls/shell32/tests/assoc.c
index beebbdf..c4de511 100644
--- a/dlls/shell32/tests/assoc.c
+++ b/dlls/shell32/tests/assoc.c
@@ -115,8 +115,11 @@ static void getstring_test(LPCWSTR assocName, HKEY progIdKey, ASSOCSTR str, LPCW
     hr = IQueryAssociations_GetString(assoc, ASSOCF_NONE, str, NULL, NULL, &len);
     if (expected_string) {
         ok_(__FILE__, line)(hr == S_FALSE, "GetString returned 0x%x, expected S_FALSE\n", hr);
-        if (hr != S_FALSE)
-            return; /* don't try to allocate memory */
+        if (hr != S_FALSE) {
+            /* don't try to allocate memory using unitialized len */
+            IQueryAssociations_Release(assoc);
+            return;
+        }
 
         buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
         ok_(__FILE__, line)(buffer != NULL, "out of memory\n");
@@ -128,6 +131,10 @@ static void getstring_test(LPCWSTR assocName, HKEY progIdKey, ASSOCSTR str, LPCW
     } else {
         ok_(__FILE__, line)(FAILED(hr), "GetString returned 0x%x, expected failure\n", hr);
     }
+
+    IQueryAssociations_Release(assoc);
+    if (buffer)
+        HeapFree(GetProcessHeap(), 0, buffer);
 }
 
 static void test_IQueryAssociations_GetString(void)
-- 
2.6.4 (Apple Git-63)




More information about the wine-patches mailing list