VMS support.
[openssl.git] / ssl / ssl_sess.c
index e06f3ad5e9e7f8f34739314993e09c4fd727312c..88d4b50c759f0e2adc30534469f09d0865970a34 100644 (file)
@@ -63,6 +63,7 @@
 
 static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
 static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s);
+static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
 static int ssl_session_num=0;
 static STACK *ssl_session_meth=NULL;
 
@@ -304,8 +305,8 @@ int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
                        while (SSL_CTX_sess_number(ctx) >
                                SSL_CTX_sess_get_cache_size(ctx))
                                {
-                               if (!SSL_CTX_remove_session(ctx,
-                                       ctx->session_cache_tail))
+                               if (!remove_session_lock(ctx,
+                                       ctx->session_cache_tail, 0))
                                        break;
                                else
                                        ctx->stats.sess_cache_full++;
@@ -317,13 +318,18 @@ int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
        }
 
 int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
+{
+       return remove_session_lock(ctx, c, 1);
+}
+
+static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
        {
        SSL_SESSION *r;
        int ret=0;
 
        if ((c != NULL) && (c->session_id_length != 0))
                {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
+               if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
                r=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);
                if (r != NULL)
                        {
@@ -331,7 +337,7 @@ int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
                        SSL_SESSION_list_remove(ctx,c);
                        }
 
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
+               if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
 
                if (ret)
                        {
@@ -371,7 +377,7 @@ void SSL_SESSION_free(SSL_SESSION *ss)
        memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH);
        memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH);
        memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH);
-       if (ss->cert != NULL) ssl_cert_free(ss->cert);
+       if (ss->sess_cert != NULL) ssl_cert_free(ss->sess_cert);
        if (ss->peer != NULL) X509_free(ss->peer);
        if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
        memset(ss,0,sizeof(*ss));