diff options
Diffstat (limited to 'src/share/classes/sun/security/pkcs11/P11Key.java')
-rw-r--r-- | src/share/classes/sun/security/pkcs11/P11Key.java | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/share/classes/sun/security/pkcs11/P11Key.java b/src/share/classes/sun/security/pkcs11/P11Key.java index b37042997..1b26f1e3e 100644 --- a/src/share/classes/sun/security/pkcs11/P11Key.java +++ b/src/share/classes/sun/security/pkcs11/P11Key.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -85,7 +85,7 @@ abstract class P11Key implements Key { // flags indicating whether the key is a token object, sensitive, extractable final boolean tokenObject, sensitive, extractable; - // weak reference notification clean up for session keys + // phantom reference notification clean up for session keys private final SessionKeyRef sessionKeyRef; P11Key(String type, Session session, long keyID, String algorithm, @@ -1051,7 +1051,12 @@ abstract class P11Key implements Key { } } -final class SessionKeyRef extends WeakReference<P11Key> +/* + * NOTE: Must use PhantomReference here and not WeakReference + * otherwise the key maybe cleared before other objects which + * still use these keys during finalization such as SSLSocket. + */ +final class SessionKeyRef extends PhantomReference<P11Key> implements Comparable<SessionKeyRef> { private static ReferenceQueue<P11Key> refQueue = new ReferenceQueue<P11Key>(); @@ -1062,14 +1067,11 @@ final class SessionKeyRef extends WeakReference<P11Key> return refQueue; } - static final private int MAX_ITERATIONS = 2; - private static void drainRefQueueBounded() { - int iterations = 0; - while (iterations < MAX_ITERATIONS) { + while (true) { SessionKeyRef next = (SessionKeyRef) refQueue.poll(); - if (next != null) next.dispose(); - ++iterations; + if (next == null) break; + next.dispose(); } } @@ -1087,7 +1089,7 @@ final class SessionKeyRef extends WeakReference<P11Key> drainRefQueueBounded(); } - void dispose() { + private void dispose() { refList.remove(this); if (session.token.isValid()) { Session newSession = null; @@ -1097,6 +1099,7 @@ final class SessionKeyRef extends WeakReference<P11Key> } catch (PKCS11Exception e) { // ignore } finally { + this.clear(); session.token.releaseSession(newSession); session.removeObject(); } |