#ifdef WIN32
/*
- * This is the tls index returned by TlsAlloc() on process init.
+ * This is the TLS index returned by TlsAlloc() on process init.
* Each thread, on thread attach in DllMain(), allocates its thread-local
* data and uses this index with TlsSetValue() to store it.
* It can then subsequently be retrieved with TlsGetValue().
*/
-static DWORD tlsIndex;
+static DWORD tlsIndex = TLS_OUT_OF_INDEXES;
/* Access thread-local data */
struct gss_eap_thread_local_data *
gssEapGetThreadLocalData(void)
{
- return TlsGetValue(tlsIndex);
+ struct gss_eap_thread_local_data *tlsData;
+
+ GSSEAP_ASSERT(tlsIndex != TLS_OUT_OF_INDEXES);
+
+ tlsData = TlsGetValue(tlsIndex);
+ if (tlsData == NULL) {
+ tlsData = GSSEAP_CALLOC(1, sizeof(*tlsData));
+ TlsSetValue(tlsIndex, tlsData);
+ }
+
+ return tlsData;
}
BOOL WINAPI
LPVOID reserved) /* reserved */
{
struct gss_eap_thread_local_data *tlsData;
+ OM_uint32 major, minor;
switch (reason) {
case DLL_PROCESS_ATTACH:
/* Allocate a TLS index. */
- gssEapInitiatorInit();
+ major = gssEapInitiatorInit(&minor);
+ if (GSS_ERROR(major))
+ return FALSE;
+
tlsIndex = TlsAlloc();
if (tlsIndex == TLS_OUT_OF_INDEXES)
return FALSE;
case DLL_THREAD_ATTACH:
/* Initialize the TLS index for this thread. */
tlsData = GSSEAP_CALLOC(1, sizeof(*tlsData));
- if (tlsData != NULL)
- TlsSetValue(tlsIndex, tlsData);
+ if (tlsData == NULL)
+ return FALSE;
+ TlsSetValue(tlsIndex, tlsData);
break;
case DLL_THREAD_DETACH:
/* Release the allocated memory for this thread. */
}
break;
case DLL_PROCESS_DETACH:
- /* Release the allocated memory for this thread. */
- tlsData = TlsGetValue(tlsIndex);
- if (tlsData != NULL)
- destroyThreadLocalData(tlsData);
/* Release the TLS index. */
TlsFree(tlsIndex);
gssEapFinalize();