1 diff --git a/ssl/ssl3con.c b/ssl/ssl3con.c
2 index 6819b03..6a4a443 100644
5 @@ -5748,7 +5748,6 @@ SSL3_ShutdownServerCache(void)
8 PZ_Unlock(symWrapKeysLock);
9 - ssl_FreeSessionCacheLocks();
13 @@ -5800,7 +5799,7 @@ getWrappingKey( sslSocket * ss,
15 pSymWrapKey = &symWrapKeys[symWrapMechIndex].symWrapKey[exchKeyType];
17 - ssl_InitSessionCacheLocks(PR_TRUE);
18 + ssl_InitSessionCacheLocks();
20 PZ_Lock(symWrapKeysLock);
22 diff --git a/ssl/sslimpl.h b/ssl/sslimpl.h
23 index 88b2eba..c4c87b4 100644
26 @@ -1924,9 +1924,7 @@ extern SECStatus ssl_InitSymWrapKeysLock(void);
28 extern SECStatus ssl_FreeSymWrapKeysLock(void);
30 -extern SECStatus ssl_InitSessionCacheLocks(PRBool lazyInit);
32 -extern SECStatus ssl_FreeSessionCacheLocks(void);
33 +extern SECStatus ssl_InitSessionCacheLocks(void);
35 /***************** platform client auth ****************/
37 diff --git a/ssl/sslnonce.c b/ssl/sslnonce.c
38 index 1326a8b..c45849d 100644
41 @@ -35,91 +35,55 @@ static PZLock * cacheLock = NULL;
42 #define LOCK_CACHE lock_cache()
43 #define UNLOCK_CACHE PZ_Unlock(cacheLock)
46 -ssl_InitClientSessionCacheLock(void)
48 - cacheLock = PZ_NewLock(nssILockCache);
49 - return cacheLock ? SECSuccess : SECFailure;
53 -ssl_FreeClientSessionCacheLock(void)
56 - PZ_DestroyLock(cacheLock);
60 - PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
64 -static PRBool LocksInitializedEarly = PR_FALSE;
65 +static PRCallOnceType lockOnce;
67 +/* FreeSessionCacheLocks is a callback from NSS_RegisterShutdown which destroys
68 + * the session cache locks on shutdown and resets them to their initial
71 -FreeSessionCacheLocks()
72 +FreeSessionCacheLocks(void* appData, void* nssData)
75 - rv1 = ssl_FreeSymWrapKeysLock();
76 - rv2 = ssl_FreeClientSessionCacheLock();
77 - if ( (SECSuccess == rv1) && (SECSuccess == rv2) ) {
82 + static const PRCallOnceType pristineCallOnce;
86 -InitSessionCacheLocks(void)
90 - rv1 = ssl_InitSymWrapKeysLock();
91 - rv2 = ssl_InitClientSessionCacheLock();
92 - if ( (SECSuccess == rv1) && (SECSuccess == rv2) ) {
95 - rc = PORT_GetError();
96 - FreeSessionCacheLocks();
101 -/* free the session cache locks if they were initialized early */
103 -ssl_FreeSessionCacheLocks()
105 - PORT_Assert(PR_TRUE == LocksInitializedEarly);
106 - if (!LocksInitializedEarly) {
108 PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
111 - FreeSessionCacheLocks();
112 - LocksInitializedEarly = PR_FALSE;
116 -static PRCallOnceType lockOnce;
117 + PZ_DestroyLock(cacheLock);
120 -/* free the session cache locks if they were initialized lazily */
121 -static SECStatus ssl_ShutdownLocks(void* appData, void* nssData)
123 - PORT_Assert(PR_FALSE == LocksInitializedEarly);
124 - if (LocksInitializedEarly) {
125 - PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
127 + rv = ssl_FreeSymWrapKeysLock();
128 + if (rv != SECSuccess) {
131 - FreeSessionCacheLocks();
132 - memset(&lockOnce, 0, sizeof(lockOnce));
134 + lockOnce = pristineCallOnce;
138 -static PRStatus initSessionCacheLocksLazily(void)
139 +/* InitSessionCacheLocks is called, protected by lockOnce, to create the
140 + * session cache locks. */
142 +InitSessionCacheLocks(void)
144 - SECStatus rv = InitSessionCacheLocks();
145 - if (SECSuccess != rv) {
148 + cacheLock = PZ_NewLock(nssILockCache);
149 + if (cacheLock == NULL) {
152 - rv = NSS_RegisterShutdown(ssl_ShutdownLocks, NULL);
153 + rv = ssl_InitSymWrapKeysLock();
154 + if (rv != SECSuccess) {
155 + PRErrorCode error = PORT_GetError();
156 + PZ_DestroyLock(cacheLock);
158 + PORT_SetError(error);
162 + rv = NSS_RegisterShutdown(FreeSessionCacheLocks, NULL);
163 PORT_Assert(SECSuccess == rv);
164 if (SECSuccess != rv) {
166 @@ -127,34 +91,18 @@ static PRStatus initSessionCacheLocksLazily(void)
170 -/* lazyInit means that the call is not happening during a 1-time
171 - * initialization function, but rather during dynamic, lazy initialization
174 -ssl_InitSessionCacheLocks(PRBool lazyInit)
175 +ssl_InitSessionCacheLocks(void)
177 - if (LocksInitializedEarly) {
182 - return (PR_SUCCESS ==
183 - PR_CallOnce(&lockOnce, initSessionCacheLocksLazily)) ?
184 - SECSuccess : SECFailure;
187 - if (SECSuccess == InitSessionCacheLocks()) {
188 - LocksInitializedEarly = PR_TRUE;
193 + return (PR_SUCCESS ==
194 + PR_CallOnce(&lockOnce, InitSessionCacheLocks)) ?
195 + SECSuccess : SECFailure;
202 - ssl_InitSessionCacheLocks(PR_TRUE);
203 + ssl_InitSessionCacheLocks();
207 diff --git a/ssl/sslsnce.c b/ssl/sslsnce.c
208 index 4d9ef38..3279200 100644
211 @@ -1352,7 +1352,7 @@ SSL_ConfigServerSessionIDCache( int maxCacheEntries,
212 PRUint32 ssl3_timeout,
213 const char * directory)
215 - ssl_InitSessionCacheLocks(PR_FALSE);
216 + ssl_InitSessionCacheLocks();
217 return SSL_ConfigServerSessionIDCacheInstance(&globalCache,
218 maxCacheEntries, ssl2_timeout, ssl3_timeout, directory, PR_FALSE);
220 @@ -1466,7 +1466,7 @@ SSL_ConfigServerSessionIDCacheWithOpt(
221 PRBool enableMPCache)
223 if (!enableMPCache) {
224 - ssl_InitSessionCacheLocks(PR_FALSE);
225 + ssl_InitSessionCacheLocks();
226 return ssl_ConfigServerSessionIDCacheInstanceWithOpt(&globalCache,
227 ssl2_timeout, ssl3_timeout, directory, PR_FALSE,
228 maxCacheEntries, maxCertCacheEntries, maxSrvNameCacheEntries);
229 @@ -1511,7 +1511,7 @@ SSL_InheritMPServerSIDCacheInstance(cacheDesc *cache, const char * envString)
230 return SECSuccess; /* already done. */
233 - ssl_InitSessionCacheLocks(PR_FALSE);
234 + ssl_InitSessionCacheLocks();
236 ssl_sid_lookup = ServerSessionIDLookup;
237 ssl_sid_cache = ServerSessionIDCache;