Increment the reference count of sessions inside the lock.

Otherwise another thread may cause the session to be destroyed first.

Change-Id: I2084a28ece11540e1b8f289553161d99395e2d1f
Reviewed-on: https://boringssl-review.googlesource.com/5231
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c
index 9ab4585..765c9d9 100644
--- a/ssl/ssl_sess.c
+++ b/ssl/ssl_sess.c
@@ -420,11 +420,10 @@
 
     CRYPTO_MUTEX_lock_read(&s->initial_ctx->lock);
     ret = lh_SSL_SESSION_retrieve(s->initial_ctx->sessions, &data);
-    CRYPTO_MUTEX_unlock(&s->initial_ctx->lock);
-
     if (ret != NULL) {
       SSL_SESSION_up_ref(ret);
     }
+    CRYPTO_MUTEX_unlock(&s->initial_ctx->lock);
   }
 
   if (try_session_cache && ret == NULL &&