소스 검색

test: fix coverity 1474468: resource leak

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14716)
Pauli 3 년 전
부모
커밋
92b3e62fdd
1개의 변경된 파일6개의 추가작업 그리고 8개의 파일을 삭제
  1. 6 8
      test/bad_dtls_test.c

+ 6 - 8
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);