summaryrefslogtreecommitdiff
path: root/test/bad_dtls_test.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-03-29 12:33:02 +1000
committerTomas Mraz <tomas@openssl.org>2021-03-30 18:57:30 +0200
commit92b3e62fdd5c85101998affe2260ac845cf09ba4 (patch)
tree6a0405ef4e84de99fbc2dea150aec69e7d840905 /test/bad_dtls_test.c
parentec3dd97019b7ec95b77d50b6f81c8d32d58d9bbf (diff)
downloadopenssl-new-92b3e62fdd5c85101998affe2260ac845cf09ba4.tar.gz
test: fix coverity 1474468: resource leak
Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14716)
Diffstat (limited to 'test/bad_dtls_test.c')
-rw-r--r--test/bad_dtls_test.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/test/bad_dtls_test.c b/test/bad_dtls_test.c
index d60daa447f..48cf45bae6 100644
--- a/test/bad_dtls_test.c
+++ b/test/bad_dtls_test.c
@@ -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);