Browse Source

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.
tis
Christoph M. Becker 3 years ago
committed by GitHub
parent
commit
8b66d2b969
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/libsodium/sodium/core.c

13
src/libsodium/sodium/core.c

@ -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

Loading…
Cancel
Save