summaryrefslogtreecommitdiff
path: root/lib/dev
diff options
context:
space:
mode:
authorTim Taubert <ttaubert@mozilla.com>2017-05-29 16:06:46 +0200
committerTim Taubert <ttaubert@mozilla.com>2017-05-29 16:06:46 +0200
commitb4a5f4d76ae30be0a830a2b009b18c60160802e8 (patch)
tree753e5d0da00c53ad272b695730e38eb5a0b0c9a5 /lib/dev
parent522c82de28794be1a0f82eae678e60d7cd37d7f3 (diff)
downloadnss-hg-b4a5f4d76ae30be0a830a2b009b18c60160802e8.tar.gz
Bug 1273678 - Own PK11SlotInfos in NSSSlot/NSSToken r=franziskus (thx=keeler)
Differential Revision: https://nss-review.dev.mozaws.net/D332
Diffstat (limited to 'lib/dev')
-rw-r--r--lib/dev/devslot.c14
-rw-r--r--lib/dev/devtoken.c11
2 files changed, 19 insertions, 6 deletions
diff --git a/lib/dev/devslot.c b/lib/dev/devslot.c
index c3c05be9a..7e8bfcd64 100644
--- a/lib/dev/devslot.c
+++ b/lib/dev/devslot.c
@@ -31,6 +31,7 @@ nssSlot_Destroy(
{
if (slot) {
if (PR_ATOMIC_DECREMENT(&slot->base.refCount) == 0) {
+ PK11_FreeSlot(slot->pk11slot);
PZ_DestroyLock(slot->base.lock);
return nssArena_Destroy(slot->base.arena);
}
@@ -224,10 +225,17 @@ NSS_IMPLEMENT NSSToken *
nssSlot_GetToken(
NSSSlot *slot)
{
- if (nssSlot_IsTokenPresent(slot)) {
- return nssToken_AddRef(slot->token);
+ NSSToken *rvToken = NULL;
+ nssSlot_EnterMonitor(slot);
+
+ /* Even if a token should be present, check `slot->token` too as it
+ * might be gone already. This would happen mostly on shutdown. */
+ if (nssSlot_IsTokenPresent(slot) && slot->token) {
+ rvToken = nssToken_AddRef(slot->token);
}
- return (NSSToken *)NULL;
+
+ nssSlot_ExitMonitor(slot);
+ return rvToken;
}
NSS_IMPLEMENT PRStatus
diff --git a/lib/dev/devtoken.c b/lib/dev/devtoken.c
index 40f2acaae..0d4c3b5a7 100644
--- a/lib/dev/devtoken.c
+++ b/lib/dev/devtoken.c
@@ -29,11 +29,16 @@ nssToken_Destroy(
{
if (tok) {
if (PR_ATOMIC_DECREMENT(&tok->base.refCount) == 0) {
+ PK11_FreeSlot(tok->pk11slot);
PZ_DestroyLock(tok->base.lock);
nssTokenObjectCache_Destroy(tok->cache);
- /* The token holds the first/last reference to the slot.
- * When the token is actually destroyed, that ref must go too.
- */
+
+ /* We're going away, let the nssSlot know in case it's held
+ * alive by someone else. Usually we should hold the last ref. */
+ nssSlot_EnterMonitor(tok->slot);
+ tok->slot->token = NULL;
+ nssSlot_ExitMonitor(tok->slot);
+
(void)nssSlot_Destroy(tok->slot);
return nssArena_Destroy(tok->base.arena);
}