summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ.C. Jones <jjones@mozilla.com>2019-09-27 21:24:52 +0000
committerJ.C. Jones <jjones@mozilla.com>2019-09-27 21:24:52 +0000
commit1a9163e5936b6e6bea8352497faadabcd08f9459 (patch)
tree339c7f28ba02a8099a20a786abe3785a28f70c36
parent058733416a418b99efd4b4091fea4d23bdcb6bae (diff)
downloadnss-hg-1a9163e5936b6e6bea8352497faadabcd08f9459.tar.gz
Bug 1508776 - Remove unneeded refcounting from SFTKSession r=mt,kjacobs
SFTKSession objects are only ever actually destroyed at PK11 session closure, as the session is always the final holder -- and asserting refCount == 1 shows that to be true. Because of that, NSC_CloseSession can just call `sftk_DestroySession` directly and leave `sftk_FreeSession` as a no-op to be removed in the future. Differential Revision: https://phabricator.services.mozilla.com/D47010
-rw-r--r--lib/softoken/pkcs11.c10
-rw-r--r--lib/softoken/pkcs11i.h2
-rw-r--r--lib/softoken/pkcs11u.c23
3 files changed, 11 insertions, 24 deletions
diff --git a/lib/softoken/pkcs11.c b/lib/softoken/pkcs11.c
index 7a5996f06..05e3ac1d4 100644
--- a/lib/softoken/pkcs11.c
+++ b/lib/softoken/pkcs11.c
@@ -2805,8 +2805,9 @@ sftk_CloseAllSessions(SFTKSlot *slot, PRBool logout)
} else {
SKIP_AFTER_FORK(PZ_Unlock(lock));
}
- if (session)
- sftk_FreeSession(session);
+ if (session) {
+ sftk_DestroySession(session);
+ }
} while (session != NULL);
}
return CKR_OK;
@@ -4044,8 +4045,6 @@ NSC_CloseSession(CK_SESSION_HANDLE hSession)
if (sftkqueue_is_queued(session, hSession, slot->head, slot->sessHashSize)) {
sessionFound = PR_TRUE;
sftkqueue_delete(session, hSession, slot->head, slot->sessHashSize);
- session->refCount--; /* can't go to zero while we hold the reference */
- PORT_Assert(session->refCount > 0);
}
PZ_Unlock(lock);
@@ -4066,9 +4065,10 @@ NSC_CloseSession(CK_SESSION_HANDLE hSession)
if (session->info.flags & CKF_RW_SESSION) {
(void)PR_ATOMIC_DECREMENT(&slot->rwSessionCount);
}
+ sftk_DestroySession(session);
+ session = NULL;
}
- sftk_FreeSession(session);
return CKR_OK;
}
diff --git a/lib/softoken/pkcs11i.h b/lib/softoken/pkcs11i.h
index 40f3cae93..fccf0f0dd 100644
--- a/lib/softoken/pkcs11i.h
+++ b/lib/softoken/pkcs11i.h
@@ -285,7 +285,6 @@ struct SFTKSessionStr {
SFTKSession *next;
SFTKSession *prev;
CK_SESSION_HANDLE handle;
- int refCount;
PZLock *objectLock;
int objectIDCount;
CK_SESSION_INFO info;
@@ -683,6 +682,7 @@ extern SFTKSlot *sftk_SlotFromSessionHandle(CK_SESSION_HANDLE handle);
extern CK_SLOT_ID sftk_SlotIDFromSessionHandle(CK_SESSION_HANDLE handle);
extern SFTKSession *sftk_SessionFromHandle(CK_SESSION_HANDLE handle);
extern void sftk_FreeSession(SFTKSession *session);
+extern void sftk_DestroySession(SFTKSession *session);
extern SFTKSession *sftk_NewSession(CK_SLOT_ID slotID, CK_NOTIFY notify,
CK_VOID_PTR pApplication, CK_FLAGS flags);
extern void sftk_update_state(SFTKSlot *slot, SFTKSession *session);
diff --git a/lib/softoken/pkcs11u.c b/lib/softoken/pkcs11u.c
index dfed660a9..1acc52e1c 100644
--- a/lib/softoken/pkcs11u.c
+++ b/lib/softoken/pkcs11u.c
@@ -1813,7 +1813,6 @@ sftk_NewSession(CK_SLOT_ID slotID, CK_NOTIFY notify, CK_VOID_PTR pApplication,
return NULL;
session->next = session->prev = NULL;
- session->refCount = 1;
session->enc_context = NULL;
session->hash_context = NULL;
session->sign_context = NULL;
@@ -1837,11 +1836,10 @@ sftk_NewSession(CK_SLOT_ID slotID, CK_NOTIFY notify, CK_VOID_PTR pApplication,
}
/* free all the data associated with a session. */
-static void
+void
sftk_DestroySession(SFTKSession *session)
{
SFTKObjectList *op, *next;
- PORT_Assert(session->refCount == 0);
/* clean out the attributes */
/* since no one is referencing us, it's safe to walk the chain
@@ -1885,31 +1883,20 @@ sftk_SessionFromHandle(CK_SESSION_HANDLE handle)
PZ_Lock(lock);
sftkqueue_find(session, handle, slot->head, slot->sessHashSize);
- if (session)
- session->refCount++;
PZ_Unlock(lock);
return (session);
}
/*
- * release a reference to a session handle
+ * release a reference to a session handle. This method of using SFTKSessions
+ * is deprecated, but the pattern should be retained until a future effort
+ * to refactor all SFTKSession users at once is completed.
*/
void
sftk_FreeSession(SFTKSession *session)
{
- PRBool destroy = PR_FALSE;
- SFTKSlot *slot = sftk_SlotFromSession(session);
- PZLock *lock = SFTK_SESSION_LOCK(slot, session->handle);
-
- PZ_Lock(lock);
- if (session->refCount == 1)
- destroy = PR_TRUE;
- session->refCount--;
- PZ_Unlock(lock);
-
- if (destroy)
- sftk_DestroySession(session);
+ return;
}
void