rem: NsCleanupTls(wPtr->slots); if (!CloseHandle(wPtr->event)) { NsThreadFatal("DllMain", "CloseHandle", GetLastError());
add: if (wPtr) { NsCleanupTls(wPtr->slots); if (!CloseHandle(wPtr->event)) { NsThreadFatal("DllMain", "CloseHandle", GetLastError()); } if (!TlsSetValue(tlskey, NULL)) { NsThreadFatal("DllMain", "TlsSetValue", GetLastError()); } ns_free(wPtr);
context: DllMain(HANDLE hModule, DWORD why, LPVOID lpReserved){    WinThread *wPtr;    switch (why) {    case DLL_PROCESS_ATTACH:	tlskey = TlsAlloc();	if (tlskey == 0xFFFFFFFF) {	    return FALSE;	}	NsInitThreads();	/* FALLTHROUGH */    case DLL_THREAD_ATTACH:	wPtr = ns_calloc(1, sizeof(WinThread));	wPtr->event = CreateEvent(NULL, TRUE, FALSE, NULL);	if (wPtr->event == NULL) {	    NsThreadFatal("DllMain", "CreateEvent", GetLastError());	}	if (!TlsSetValue(tlskey, wPtr)) {	    NsThreadFatal("DllMain", "TlsSetValue", GetLastError());	}	break;    case DLL_THREAD_DETACH:	/*	 * Note this code does not execute for the final thread on	 * exit because the TLS callbacks may invoke code from an	 * unloaded DLL, e.g., Tcl.	 */	wPtr = TlsGetValue(tlskey);	NsCleanupTls(wPtr->slots);	if (!CloseHandle(wPtr->event)) {	    NsThreadFatal("DllMain", "CloseHandle", GetLastError());	}	if (!TlsSetValue(tlskey, NULL)) {	    NsThreadFatal("DllMain", "TlsSetValue", GetLastError());	}	ns_free(wPtr);	break;    case DLL_PROCESS_DETACH:	if (!TlsFree(tlskey)) {	    NsThreadFatal("DllMain", "TlsFree", GetLastError());	}	break;    }    return TRUE;}