more cleanup of TLD
[moonshot.git] / moonshot / mech_eap / util_tld.c
index f6feeba..10e3359 100644 (file)
@@ -51,7 +51,7 @@ destroyThreadLocalData(struct gss_eap_thread_local_data *tld)
 #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().
@@ -62,7 +62,13 @@ static DWORD tlsIndex;
 struct gss_eap_thread_local_data *
 gssEapGetThreadLocalData(void)
 {
-    return TlsGetValue(tlsIndex);
+    struct gss_eap_thread_local_data *tld;
+
+    tld = TlsGetValue(tlsIndex);
+
+    GSSEAP_ASSERT(tld != NULL);
+
+    return tld;
 }
 
 BOOL WINAPI
@@ -71,11 +77,15 @@ DllMain(HINSTANCE hDLL,     /* DLL module handle */
         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;
@@ -95,10 +105,6 @@ DllMain(HINSTANCE hDLL,     /* DLL module handle */
             }
             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();