test: fix coverity 1475941: resource leak
authorPauli <ppzgs1@gmail.com>
Sun, 4 Apr 2021 07:58:32 +0000 (17:58 +1000)
committerPauli <pauli@openssl.org>
Wed, 7 Apr 2021 13:30:42 +0000 (23:30 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14769)

test/dhtest.c

index 836d800c29d0e66026cd340cef688d24025d90ef..294c9e3f567a07edbf0ad95c1bfc3956676aee67 100644 (file)
@@ -257,8 +257,10 @@ static int dh_computekey_range_test(void)
         goto err;
 
     if (!TEST_true(BN_set_word(priv, 1))
-        || !TEST_true(DH_set0_key(dh, NULL, priv))
-        || !TEST_true(BN_set_word(pub, 1)))
+        || !TEST_true(DH_set0_key(dh, NULL, priv)))
+        goto err;
+    priv = NULL;
+    if (!TEST_true(BN_set_word(pub, 1)))
         goto err;
 
     /* Given z = pub ^ priv mod p */
@@ -282,6 +284,7 @@ static int dh_computekey_range_test(void)
     ret = 1;
 err:
     OPENSSL_free(buf);
+    BN_free(priv);
     BN_free(pub);
     BN_free(g);
     BN_free(q);