From 2e2c1873b6f4aba8ab18e8a3bc1acc4777ea611e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 28 Nov 2023 14:00:48 -0500 Subject: [PATCH] Remove lockless peak from sessions managment We will always pay the price of a lock, but this is the more robust thing to do for now. Fixes: CID 468681 CID 468678 Signed-off-by: Simo Sorce --- src/session.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/session.c b/src/session.c index 9f16e278..cddd2ead 100644 --- a/src/session.c +++ b/src/session.c @@ -957,22 +957,16 @@ void p11prov_return_session(P11PROV_SESSION *session) pool = session->pool; if (pool) { - /* peek at the pool lockless worst case we waste some time */ - if (pool->open_sessions >= pool->max_cached_sessions) { - /* not much we can do if this fails, - * but only accounting will be a bit off */ - - /* LOCKED SECTION ------------- */ - if (MUTEX_LOCK(pool) == CKR_OK) { - if (pool->open_sessions >= pool->max_cached_sessions - && session != pool->login_session) { - token_session_close(session); - pool->open_sessions--; - } - (void)MUTEX_UNLOCK(pool); + /* LOCKED SECTION ------------- */ + if (MUTEX_LOCK(pool) == CKR_OK) { + if (pool->open_sessions >= pool->max_cached_sessions + && session != pool->login_session) { + token_session_close(session); + pool->open_sessions--; } - /* ------------- LOCKED SECTION */ + (void)MUTEX_UNLOCK(pool); } + /* ------------- LOCKED SECTION */ } ret = MUTEX_LOCK(session);