Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=29974 Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/uxtheme/msstyles.c | 9 ++++++++- dlls/uxtheme/msstyles.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c index d834c9604b9..8377ca9ebce 100644 --- a/dlls/uxtheme/msstyles.c +++ b/dlls/uxtheme/msstyles.c @@ -446,6 +446,7 @@ static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWST
cur = heap_alloc(sizeof(*cur)); cur->signature = THEME_CLASS_SIGNATURE; + cur->refcount = 0; cur->hTheme = tf->hTheme; lstrcpyW(cur->szAppName, pszAppName); lstrcpyW(cur->szClassName, pszClassName); @@ -1030,6 +1031,7 @@ PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList, U TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList)); cls->tf = tfActiveTheme; cls->tf->dwRefCount++; + InterlockedIncrement(&cls->refcount); cls->dpi = dpi; } return cls; @@ -1049,6 +1051,8 @@ PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList, U */ HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc) { + LONG refcount; + __TRY { if (tc->signature != THEME_CLASS_SIGNATURE) @@ -1066,7 +1070,10 @@ HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc) return E_HANDLE; }
- MSSTYLES_CloseThemeFile (tc->tf); + refcount = InterlockedDecrement(&tc->refcount); + /* Some buggy apps may double free HTHEME handles */ + if (refcount >= 0) + MSSTYLES_CloseThemeFile(tc->tf); return S_OK; }
diff --git a/dlls/uxtheme/msstyles.h b/dlls/uxtheme/msstyles.h index 89937227ee2..8db0aa4c03c 100644 --- a/dlls/uxtheme/msstyles.h +++ b/dlls/uxtheme/msstyles.h @@ -50,6 +50,7 @@ struct _THEME_FILE;
typedef struct _THEME_CLASS { DWORD signature; + LONG refcount; HMODULE hTheme; struct _THEME_FILE* tf; WCHAR szAppName[MAX_THEME_APP_NAME];