Fix a memory leak in tls_new_record_layer
authorMatt Caswell <matt@openssl.org>
Wed, 16 Aug 2023 11:15:07 +0000 (12:15 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 17 Aug 2023 19:35:53 +0000 (21:35 +0200)
If setting the crypto state has failed then memory might have been
partially allocated to fields within the partially constructed record
layer. We need to call tls_int_free() to properly free it.

Found by the reproducible error patch in openssl#21668

Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21753)

ssl/record/methods/tls_common.c

index 4cfeddca431bc9eaa5c241484b55fa649726c0f4..505e13316180bf0a32406a3576b49a5571368995 100644 (file)
@@ -1411,7 +1411,7 @@ tls_new_record_layer(OSSL_LIB_CTX *libctx, const char *propq, int vers,
 
  err:
     if (ret != OSSL_RECORD_RETURN_SUCCESS) {
-        OPENSSL_free(*retrl);
+        tls_int_free(*retrl);
         *retrl = NULL;
     }
     return ret;