diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index 98b61a20..b3528aaa 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -156,6 +156,8 @@ static CK_C_INITIALIZE_ARGS _def_locks = { #endif /* PKCS11_THREAD_LOCKING */ static CK_C_INITIALIZE_ARGS_PTR global_locking; +static CK_C_INITIALIZE_ARGS app_locking = { + NULL, NULL, NULL, NULL, 0, NULL }; static void *global_lock = NULL; #ifdef HAVE_OS_LOCKING static CK_C_INITIALIZE_ARGS_PTR default_mutex_funcs = &_def_locks; @@ -914,6 +916,8 @@ sc_pkcs11_init_lock(CK_C_INITIALIZE_ARGS_PTR args) if (args->pReserved != NULL_PTR) return CKR_ARGUMENTS_BAD; + app_locking = *args; + /* If the app tells us OS locking is okay, * use that. Otherwise use the supplied functions. */ @@ -929,13 +933,13 @@ sc_pkcs11_init_lock(CK_C_INITIALIZE_ARGS_PTR args) /* Based on PKCS#11 v2.11 11.4 */ if (applock && oslock) { /* Shall be used in threaded environment, prefer app provided locking */ - global_locking = args; + global_locking = &app_locking; } else if (!applock && oslock) { /* Shall be used in threaded environment, must use operating system locking */ global_locking = default_mutex_funcs; } else if (applock && !oslock) { /* Shall be used in threaded environment, must use app provided locking */ - global_locking = args; + global_locking = &app_locking; } else if (!applock && !oslock) { /* Shall not be used in threaded environment, use operating system locking */ global_locking = default_mutex_funcs;