summaryrefslogtreecommitdiffstats
path: root/src/ccapi/lib/win/dllmain.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/ccapi/lib/win/dllmain.cxx')
-rw-r--r--src/ccapi/lib/win/dllmain.cxx27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/ccapi/lib/win/dllmain.cxx b/src/ccapi/lib/win/dllmain.cxx
index f9d1e2a437..82cacad9c8 100644
--- a/src/ccapi/lib/win/dllmain.cxx
+++ b/src/ccapi/lib/win/dllmain.cxx
@@ -98,13 +98,13 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, // DLL module handle
// The attached process creates a new thread:
case DLL_THREAD_ATTACH:
- // Initialize the TLS index for this thread:
- ptspdata = (struct tspdata*) LocalAlloc(LPTR, sizeof(struct tspdata));
- cci_debug_printf("%s DLL_THREAD_ATTACH; tsp*:0x%X", __FUNCTION__, ptspdata);
- if (ptspdata == NULL) return FALSE;
- fIgnore = TlsSetValue(dwTlsIndex, ptspdata);
-
- memset(ptspdata, 0, sizeof(struct tspdata));
+ cci_debug_printf("%s DLL_THREAD_ATTACH", __FUNCTION__);
+ // Don't actually rely on this case for allocation of resources.
+ // Applications (like SecureCRT) may have threads already
+ // created (say 'A' and 'B') before the dll is loaded. If the dll
+ // is loaded in thread 'A' but then used in thread 'B', thread 'B'
+ // will never execute this code.
+ fIgnore = TlsSetValue(dwTlsIndex, NULL);
// Do not call cci_ipc_thread_init() yet; defer until we actually
// need it. On XP, cci_ipc_thread_init() will cause additional
@@ -116,10 +116,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, // DLL module handle
// The thread of the attached process terminates:
case DLL_THREAD_DETACH:
cci_debug_printf("%s DLL_THREAD_DETACH", __FUNCTION__);
- // Release the allocated memory for this thread:
+ // Release the allocated memory for this thread
ptspdata = (struct tspdata*)TlsGetValue(dwTlsIndex);
if (ptspdata != NULL) {
- LocalFree((HLOCAL) ptspdata);
+ free(ptspdata);
TlsSetValue(dwTlsIndex, NULL);
}
break;
@@ -183,11 +183,16 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, // DLL module handle
// Release the allocated memory for this thread:
ptspdata = (struct tspdata*)TlsGetValue(dwTlsIndex);
- if (ptspdata != NULL) LocalFree((HLOCAL) ptspdata);
+ if (ptspdata != NULL)
+ free(ptspdata);
TlsFree(dwTlsIndex); // Release the TLS index.
+ // Ideally, we would enumerate all other threads here and
+ // release their thread local storage as well.
break;
- default: break;
+ default:
+ cci_debug_printf("%s unexpected reason %d", __FUNCTION__, fdwReason);
+ break;
}
UNREFERENCED_PARAMETER(hinstDLL); // no whining!