Commit f970db94 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

imm32: Fix crash in DllMain when FreeLibrary is called from a thread which…

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.
parent fe0da5e5
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment