1 diff -pu a/nss/lib/ssl/ssl3con.c b/nss/lib/ssl/ssl3con.c
2 --- a/nss/lib/ssl/ssl3con.c 2014-01-17 18:10:16.783281701 -0800
3 +++ b/nss/lib/ssl/ssl3con.c 2014-01-17 18:11:03.734060469 -0800
4 @@ -5678,7 +5678,6 @@ SSL3_ShutdownServerCache(void)
7 PZ_Unlock(symWrapKeysLock);
8 - ssl_FreeSessionCacheLocks();
12 @@ -5730,7 +5729,7 @@ getWrappingKey( sslSocket * ss,
14 pSymWrapKey = &symWrapKeys[symWrapMechIndex].symWrapKey[exchKeyType];
16 - ssl_InitSessionCacheLocks(PR_TRUE);
17 + ssl_InitSessionCacheLocks();
19 PZ_Lock(symWrapKeysLock);
21 diff -pu a/nss/lib/ssl/sslimpl.h b/nss/lib/ssl/sslimpl.h
22 --- a/nss/lib/ssl/sslimpl.h 2014-01-17 18:10:16.793281867 -0800
23 +++ b/nss/lib/ssl/sslimpl.h 2014-01-17 18:11:03.734060469 -0800
24 @@ -1913,9 +1913,7 @@ extern SECStatus ssl_InitSymWrapKeysLock
26 extern SECStatus ssl_FreeSymWrapKeysLock(void);
28 -extern SECStatus ssl_InitSessionCacheLocks(PRBool lazyInit);
30 -extern SECStatus ssl_FreeSessionCacheLocks(void);
31 +extern SECStatus ssl_InitSessionCacheLocks(void);
33 /***************** platform client auth ****************/
35 diff -pu a/nss/lib/ssl/sslnonce.c b/nss/lib/ssl/sslnonce.c
36 --- a/nss/lib/ssl/sslnonce.c 2014-01-17 17:59:03.242109996 -0800
37 +++ b/nss/lib/ssl/sslnonce.c 2014-01-17 18:11:03.754060801 -0800
38 @@ -35,91 +35,55 @@ static PZLock * cacheLock = NULL;
39 #define LOCK_CACHE lock_cache()
40 #define UNLOCK_CACHE PZ_Unlock(cacheLock)
43 -ssl_InitClientSessionCacheLock(void)
45 - cacheLock = PZ_NewLock(nssILockCache);
46 - return cacheLock ? SECSuccess : SECFailure;
50 -ssl_FreeClientSessionCacheLock(void)
53 - PZ_DestroyLock(cacheLock);
57 - PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
61 -static PRBool LocksInitializedEarly = PR_FALSE;
64 -FreeSessionCacheLocks()
67 - rv1 = ssl_FreeSymWrapKeysLock();
68 - rv2 = ssl_FreeClientSessionCacheLock();
69 - if ( (SECSuccess == rv1) && (SECSuccess == rv2) ) {
74 +static PRCallOnceType lockOnce;
76 +/* FreeSessionCacheLocks is a callback from NSS_RegisterShutdown which destroys
77 + * the session cache locks on shutdown and resets them to their initial
80 -InitSessionCacheLocks(void)
81 +FreeSessionCacheLocks(void* appData, void* nssData)
85 - rv1 = ssl_InitSymWrapKeysLock();
86 - rv2 = ssl_InitClientSessionCacheLock();
87 - if ( (SECSuccess == rv1) && (SECSuccess == rv2) ) {
90 - rc = PORT_GetError();
91 - FreeSessionCacheLocks();
95 + static const PRCallOnceType pristineCallOnce;
98 -/* free the session cache locks if they were initialized early */
100 -ssl_FreeSessionCacheLocks()
102 - PORT_Assert(PR_TRUE == LocksInitializedEarly);
103 - if (!LocksInitializedEarly) {
105 PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
108 - FreeSessionCacheLocks();
109 - LocksInitializedEarly = PR_FALSE;
113 -static PRCallOnceType lockOnce;
114 + PZ_DestroyLock(cacheLock);
117 -/* free the session cache locks if they were initialized lazily */
118 -static SECStatus ssl_ShutdownLocks(void* appData, void* nssData)
120 - PORT_Assert(PR_FALSE == LocksInitializedEarly);
121 - if (LocksInitializedEarly) {
122 - PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
124 + rv = ssl_FreeSymWrapKeysLock();
125 + if (rv != SECSuccess) {
128 - FreeSessionCacheLocks();
129 - memset(&lockOnce, 0, sizeof(lockOnce));
131 + lockOnce = pristineCallOnce;
135 -static PRStatus initSessionCacheLocksLazily(void)
136 +/* InitSessionCacheLocks is called, protected by lockOnce, to create the
137 + * session cache locks. */
139 +InitSessionCacheLocks(void)
141 - SECStatus rv = InitSessionCacheLocks();
142 - if (SECSuccess != rv) {
145 + cacheLock = PZ_NewLock(nssILockCache);
146 + if (cacheLock == NULL) {
149 - rv = NSS_RegisterShutdown(ssl_ShutdownLocks, NULL);
150 + rv = ssl_InitSymWrapKeysLock();
151 + if (rv != SECSuccess) {
152 + PRErrorCode error = PORT_GetError();
153 + PZ_DestroyLock(cacheLock);
155 + PORT_SetError(error);
159 + rv = NSS_RegisterShutdown(FreeSessionCacheLocks, NULL);
160 PORT_Assert(SECSuccess == rv);
161 if (SECSuccess != rv) {
163 @@ -127,34 +91,18 @@ static PRStatus initSessionCacheLocksLaz
167 -/* lazyInit means that the call is not happening during a 1-time
168 - * initialization function, but rather during dynamic, lazy initialization
171 -ssl_InitSessionCacheLocks(PRBool lazyInit)
172 +ssl_InitSessionCacheLocks(void)
174 - if (LocksInitializedEarly) {
179 - return (PR_SUCCESS ==
180 - PR_CallOnce(&lockOnce, initSessionCacheLocksLazily)) ?
181 - SECSuccess : SECFailure;
184 - if (SECSuccess == InitSessionCacheLocks()) {
185 - LocksInitializedEarly = PR_TRUE;
190 + return (PR_SUCCESS ==
191 + PR_CallOnce(&lockOnce, InitSessionCacheLocks)) ?
192 + SECSuccess : SECFailure;
199 - ssl_InitSessionCacheLocks(PR_TRUE);
200 + ssl_InitSessionCacheLocks();
204 diff -pu a/nss/lib/ssl/sslsnce.c b/nss/lib/ssl/sslsnce.c
205 --- a/nss/lib/ssl/sslsnce.c 2014-01-17 17:49:26.072517368 -0800
206 +++ b/nss/lib/ssl/sslsnce.c 2014-01-17 18:11:03.774061133 -0800
207 @@ -1353,7 +1353,7 @@ SSL_ConfigServerSessionIDCache( int
208 PRUint32 ssl3_timeout,
209 const char * directory)
211 - ssl_InitSessionCacheLocks(PR_FALSE);
212 + ssl_InitSessionCacheLocks();
213 return SSL_ConfigServerSessionIDCacheInstance(&globalCache,
214 maxCacheEntries, ssl2_timeout, ssl3_timeout, directory, PR_FALSE);
216 @@ -1467,7 +1467,7 @@ SSL_ConfigServerSessionIDCacheWithOpt(
217 PRBool enableMPCache)
219 if (!enableMPCache) {
220 - ssl_InitSessionCacheLocks(PR_FALSE);
221 + ssl_InitSessionCacheLocks();
222 return ssl_ConfigServerSessionIDCacheInstanceWithOpt(&globalCache,
223 ssl2_timeout, ssl3_timeout, directory, PR_FALSE,
224 maxCacheEntries, maxCertCacheEntries, maxSrvNameCacheEntries);
225 @@ -1512,7 +1512,7 @@ SSL_InheritMPServerSIDCacheInstance(cach
226 return SECSuccess; /* already done. */
229 - ssl_InitSessionCacheLocks(PR_FALSE);
230 + ssl_InitSessionCacheLocks();
232 ssl_sid_lookup = ServerSessionIDLookup;
233 ssl_sid_cache = ServerSessionIDCache;