]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC APL: Avoid having a mutex variable where not needed
authorHugo Landau <hlandau@openssl.org>
Sun, 10 Mar 2024 00:29:07 +0000 (00:29 +0000)
committerViktor Dukhovni <openssl-users@dukhovni.org>
Wed, 11 Sep 2024 08:35:22 +0000 (18:35 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23334)

ssl/quic/quic_impl.c
ssl/quic/quic_local.h

index 39307621d2bb351abe0f9089000ada6b655e9cab..10c1ee859e7031aa10b5190a06c721b23d228448 100644 (file)
@@ -551,11 +551,11 @@ static void qc_cleanup(QUIC_CONNECTION *qc, int have_lock)
         qc->engine = NULL;
     }
 
+#if defined(OPENSSL_THREADS)
     if (have_lock)
         /* tsan doesn't like freeing locked mutexes */
         ossl_crypto_mutex_unlock(qc->mutex);
 
-#if defined(OPENSSL_THREADS)
     if (qc->listener == NULL)
         ossl_crypto_mutex_free(&qc->mutex);
 #endif
@@ -569,7 +569,9 @@ static void quic_free_listener(QCTX *ctx)
     ossl_quic_port_drop_incoming(ctx->ql->port);
     ossl_quic_port_free(ctx->ql->port);
     ossl_quic_engine_free(ctx->ql->engine);
+#if defined(OPENSSL_THREADS)
     ossl_crypto_mutex_free(&ctx->ql->mutex);
+#endif
 }
 
 QUIC_TAKES_LOCK
@@ -1644,7 +1646,9 @@ static int create_channel(QUIC_CONNECTION *qc, SSL_CTX *ctx)
 
     engine_args.libctx        = ctx->libctx;
     engine_args.propq         = ctx->propq;
+#if defined(OPENSSL_THREADS)
     engine_args.mutex         = qc->mutex;
+#endif
     engine_args.now_cb        = get_time_cb;
     engine_args.now_cb_arg    = qc;
     qc->engine = ossl_quic_engine_new(&engine_args);
@@ -4068,7 +4072,9 @@ SSL *ossl_quic_new_listener(SSL_CTX *ctx, uint64_t flags)
 
     engine_args.libctx  = ctx->libctx;
     engine_args.propq   = ctx->propq;
+#if defined(OPENSSL_THREADS)
     engine_args.mutex   = ql->mutex;
+#endif
     if ((ql->engine = ossl_quic_engine_new(&engine_args)) == NULL) {
         QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL);
         goto err;
@@ -4097,6 +4103,9 @@ err:
     if (ql != NULL)
         ossl_quic_engine_free(ql->engine);
 
+#if defined(OPENSSL_THREADS)
+    ossl_crypto_mutex_free(&ql->mutex);
+#endif
     OPENSSL_free(ql);
     return NULL;
 }
@@ -4214,7 +4223,9 @@ static QUIC_CONNECTION *create_qc_from_incoming_conn(QUIC_LISTENER *ql, QUIC_CHA
     qc->engine                  = ql->engine;
     qc->port                    = ql->port;
     qc->ch                      = ch;
+#if defined(OPENSSL_THREADS)
     qc->mutex                   = ql->mutex;
+#endif
     qc->tls                     = ossl_quic_channel_get0_tls(ch);
     qc->last_net_bio_epoch      = UINT64_MAX;
     qc->started                 = 1;
index 059251506e49c2b564905ea09f4e19cee1376951..85c73fe6c713ee225b240f7fd9dcf36d476f2804 100644 (file)
@@ -162,7 +162,9 @@ struct quic_conn_st {
      * The mutex used to synchronise access to the QUIC_CHANNEL. We own this but
      * provide it to the channel.
      */
+#if defined(OPENSSL_THREADS)
     CRYPTO_MUTEX                    *mutex;
+#endif
 
     /*
      * If we have a default stream attached, this is the internal XSO
@@ -269,11 +271,13 @@ struct quic_listener_st {
     /* The QUIC port representing the QUIC listener and socket. */
     QUIC_PORT                       *port;
 
+#if defined(OPENSSL_THREADS)
     /*
      * The mutex used to synchronise access to the QUIC_ENGINE. We own this but
      * provide it to the engine.
      */
     CRYPTO_MUTEX                    *mutex;
+#endif
 
     /* Have we started listening yet? */
     unsigned int                    listening               : 1;