Delete critical section on DLL_PROCESS_DETACH (#1058)

To explicitly release all allocated resources on shutdown on Windows, we delete the critical section on `DLL_PROCESS_DETACH`.

We do not employ any locking to avoid any potential deadlock.  In case of normal
DLL unloading there is no need to, and in case of forced unloading all bets are likely off anyway.
This commit is contained in:
Christoph M. Becker
2021-05-22 10:26:13 +02:00
committed by GitHub
parent 710b2d3963
commit 8b66d2b969
+13
View File
@@ -214,3 +214,16 @@ sodium_set_misuse_handler(void (*handler)(void))
}
return 0;
}
#ifdef _WIN32
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
switch (fdwReason) {
case DLL_PROCESS_DETACH:
if (_sodium_lock_initialized == 2) {
DeleteCriticalSection(&_sodium_lock);
}
break;
}
return TRUE;
}
#endif