Rob Shearman : imm32: Fix crash in DllMain when FreeLibrary is called from a thread which existed before the DLL was loaded .
Alexandre Julliard
julliard at winehq.org
Tue Feb 24 10:21:53 CST 2009
Module: wine
Branch: master
Commit: f970db947a1cb1aedcec4e7adb946428c7fb6e96
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f970db947a1cb1aedcec4e7adb946428c7fb6e96
Author: Rob Shearman <robertshearman at gmail.com>
Date: Tue Feb 24 14:50:55 2009 +0000
imm32: Fix crash in DllMain when FreeLibrary is called from a thread which existed before the DLL was loaded.
The code in IMM_FreeThreadData shouldn't assume that thread data will
always have been created, so check for NULL data.
Make loading the DLL more robust against errors.
---
dlls/imm32/imm.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c
index bb50e5e..82868be 100644
--- a/dlls/imm32/imm.c
+++ b/dlls/imm32/imm.c
@@ -223,22 +223,28 @@ static IMMThreadData* IMM_GetThreadData(void)
return TlsGetValue(tlsIndex);
}
-static void IMM_InitThreadData(void)
+static BOOL IMM_InitThreadData(void)
{
IMMThreadData* data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(IMMThreadData));
+ if (!data) return FALSE;
+
TlsSetValue(tlsIndex,data);
TRACE("Thread Data Created\n");
+ return TRUE;
}
static void IMM_FreeThreadData(void)
{
IMMThreadData* data = TlsGetValue(tlsIndex);
- IMM_DestroyContext(data->defaultContext);
- DestroyWindow(data->hwndDefault);
- HeapFree(GetProcessHeap(),0,data);
- TRACE("Thread Data Destroyed\n");
+ if (data)
+ {
+ IMM_DestroyContext(data->defaultContext);
+ DestroyWindow(data->hwndDefault);
+ HeapFree(GetProcessHeap(),0,data);
+ TRACE("Thread Data Destroyed\n");
+ }
}
static HMODULE LoadDefaultWineIME(void)
@@ -378,7 +384,8 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
case DLL_PROCESS_ATTACH:
IMM_RegisterMessages();
tlsIndex = TlsAlloc();
- IMM_InitThreadData();
+ if (tlsIndex == TLS_OUT_OF_INDEXES || !IMM_InitThreadData())
+ return FALSE;
break;
case DLL_THREAD_ATTACH:
IMM_InitThreadData();
More information about the wine-cvs
mailing list