test: fix coverity 1474468: resource leak

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14716)
This commit is contained in:
Pauli 2021-03-29 12:33:02 +10:00 committed by Tomas Mraz
parent ec3dd97019
commit 92b3e62fdd

View File

@ -281,8 +281,8 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
static unsigned char seq[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static unsigned char ver[2] = { 0x01, 0x00 }; /* DTLS1_BAD_VER */
unsigned char lenbytes[2];
EVP_MAC *hmac;
EVP_MAC_CTX *ctx;
EVP_MAC *hmac = NULL;
EVP_MAC_CTX *ctx = NULL;
EVP_CIPHER_CTX *enc_ctx = NULL;
unsigned char iv[16];
unsigned char pad;
@ -306,12 +306,9 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
memcpy(enc, msg, len);
/* Append HMAC to data */
if ((hmac = EVP_MAC_fetch(NULL, "HMAC", NULL)) == NULL)
return 0;
ctx = EVP_MAC_CTX_new(hmac);
EVP_MAC_free(hmac);
if (ctx == NULL)
return 0;
if (!TEST_ptr(hmac = EVP_MAC_fetch(NULL, "HMAC", NULL))
|| !TEST_ptr(ctx = EVP_MAC_CTX_new(hmac)))
goto end;
params[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
"SHA1", 0);
params[1] = OSSL_PARAM_construct_end();
@ -354,6 +351,7 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
BIO_write(rbio, enc, len);
ret = 1;
end:
EVP_MAC_free(hmac);
EVP_MAC_CTX_free(ctx);
EVP_CIPHER_CTX_free(enc_ctx);
OPENSSL_free(enc);