summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2021-02-15 18:31:36 +0100
committerRichard Levitte <levitte@openssl.org>2021-04-18 10:01:31 +0200
commit543e740b95e303790f8fe6ec59458b4ecdcfb56c (patch)
tree261354d5f3154847e0edc9cae3f81d4f14a855ee /crypto
parentFix typo in aesccm.c (diff)
downloadopenssl-543e740b95e303790f8fe6ec59458b4ecdcfb56c.tar.xz
openssl-543e740b95e303790f8fe6ec59458b4ecdcfb56c.zip
Standard style for all EVP_xxx_free routines
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14193)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/evp/asymcipher.c20
-rw-r--r--crypto/evp/digest.c2
-rw-r--r--crypto/evp/evp_enc.c4
-rw-r--r--crypto/evp/evp_rand.c50
-rw-r--r--crypto/evp/exchange.c20
-rw-r--r--crypto/evp/kdf_lib.c12
-rw-r--r--crypto/evp/kdf_meth.c20
-rw-r--r--crypto/evp/kem.c21
-rw-r--r--crypto/evp/mac_lib.c12
-rw-r--r--crypto/evp/signature.c20
10 files changed, 93 insertions, 88 deletions
diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c
index 08c8fb0088..feabe0a793 100644
--- a/crypto/evp/asymcipher.c
+++ b/crypto/evp/asymcipher.c
@@ -391,16 +391,16 @@ static void *evp_asym_cipher_from_algorithm(int name_id,
void EVP_ASYM_CIPHER_free(EVP_ASYM_CIPHER *cipher)
{
- if (cipher != NULL) {
- int i;
-
- CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock);
- if (i > 0)
- return;
- ossl_provider_free(cipher->prov);
- CRYPTO_THREAD_lock_free(cipher->lock);
- OPENSSL_free(cipher);
- }
+ int i;
+
+ if (cipher == NULL)
+ return;
+ CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock);
+ if (i > 0)
+ return;
+ ossl_provider_free(cipher->prov);
+ CRYPTO_THREAD_lock_free(cipher->lock);
+ OPENSSL_free(cipher);
}
int EVP_ASYM_CIPHER_up_ref(EVP_ASYM_CIPHER *cipher)
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 2e517d2f45..82e43f2eb1 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -118,9 +118,7 @@ void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
return;
EVP_MD_CTX_reset(ctx);
-
OPENSSL_free(ctx);
- return;
}
static int evp_md_init_internal(EVP_MD_CTX *ctx, const EVP_MD *type,
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index 2e4a3227a1..9073312dfd 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -68,6 +68,8 @@ EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
{
+ if (ctx == NULL)
+ return;
EVP_CIPHER_CTX_reset(ctx);
OPENSSL_free(ctx);
}
@@ -1608,7 +1610,7 @@ void EVP_CIPHER_free(EVP_CIPHER *cipher)
{
int i;
- if (cipher == NULL)
+ if (cipher == NULL || cipher->prov == NULL)
return;
CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock);
diff --git a/crypto/evp/evp_rand.c b/crypto/evp/evp_rand.c
index 2444be5dea..cdcc88a9ac 100644
--- a/crypto/evp/evp_rand.c
+++ b/crypto/evp/evp_rand.c
@@ -62,18 +62,19 @@ static int evp_rand_up_ref(void *vrand)
return 1;
}
-static void evp_rand_free(void *vrand){
+static void evp_rand_free(void *vrand)
+{
EVP_RAND *rand = (EVP_RAND *)vrand;
int ref = 0;
- if (rand != NULL) {
- CRYPTO_DOWN_REF(&rand->refcnt, &ref, rand->refcnt_lock);
- if (ref <= 0) {
- ossl_provider_free(rand->prov);
- CRYPTO_THREAD_lock_free(rand->refcnt_lock);
- OPENSSL_free(rand);
- }
- }
+ if (rand == NULL)
+ return;
+ CRYPTO_DOWN_REF(&rand->refcnt, &ref, rand->refcnt_lock);
+ if (ref > 0)
+ return;
+ ossl_provider_free(rand->prov);
+ CRYPTO_THREAD_lock_free(rand->refcnt_lock);
+ OPENSSL_free(rand);
}
static void *evp_rand_new(void)
@@ -369,21 +370,22 @@ EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent)
void EVP_RAND_CTX_free(EVP_RAND_CTX *ctx)
{
- if (ctx != NULL) {
- int ref = 0;
-
- CRYPTO_DOWN_REF(&ctx->refcnt, &ref, ctx->refcnt_lock);
- if (ref <= 0) {
- EVP_RAND_CTX *parent = ctx->parent;
-
- ctx->meth->freectx(ctx->data);
- ctx->data = NULL;
- EVP_RAND_free(ctx->meth);
- CRYPTO_THREAD_lock_free(ctx->refcnt_lock);
- OPENSSL_free(ctx);
- EVP_RAND_CTX_free(parent);
- }
- }
+ int ref = 0;
+ EVP_RAND_CTX *parent;
+
+ if (ctx == NULL)
+ return;
+
+ CRYPTO_DOWN_REF(&ctx->refcnt, &ref, ctx->refcnt_lock);
+ if (ref > 0)
+ return;
+ parent = ctx->parent;
+ ctx->meth->freectx(ctx->data);
+ ctx->data = NULL;
+ EVP_RAND_free(ctx->meth);
+ CRYPTO_THREAD_lock_free(ctx->refcnt_lock);
+ OPENSSL_free(ctx);
+ EVP_RAND_CTX_free(parent);
}
EVP_RAND *EVP_RAND_CTX_rand(EVP_RAND_CTX *ctx)
diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c
index 07d5e4ab9b..7ec2ad760b 100644
--- a/crypto/evp/exchange.c
+++ b/crypto/evp/exchange.c
@@ -142,16 +142,16 @@ static void *evp_keyexch_from_algorithm(int name_id,
void EVP_KEYEXCH_free(EVP_KEYEXCH *exchange)
{
- if (exchange != NULL) {
- int i;
-
- CRYPTO_DOWN_REF(&exchange->refcnt, &i, exchange->lock);
- if (i > 0)
- return;
- ossl_provider_free(exchange->prov);
- CRYPTO_THREAD_lock_free(exchange->lock);
- OPENSSL_free(exchange);
- }
+ int i;
+
+ if (exchange == NULL)
+ return;
+ CRYPTO_DOWN_REF(&exchange->refcnt, &i, exchange->lock);
+ if (i > 0)
+ return;
+ ossl_provider_free(exchange->prov);
+ CRYPTO_THREAD_lock_free(exchange->lock);
+ OPENSSL_free(exchange);
}
int EVP_KEYEXCH_up_ref(EVP_KEYEXCH *exchange)
diff --git a/crypto/evp/kdf_lib.c b/crypto/evp/kdf_lib.c
index 1a1074b21b..b995e8fc5a 100644
--- a/crypto/evp/kdf_lib.c
+++ b/crypto/evp/kdf_lib.c
@@ -47,12 +47,12 @@ EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf)
void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx)
{
- if (ctx != NULL) {
- ctx->meth->freectx(ctx->data);
- ctx->data = NULL;
- EVP_KDF_free(ctx->meth);
- OPENSSL_free(ctx);
- }
+ if (ctx == NULL)
+ return;
+ ctx->meth->freectx(ctx->data);
+ ctx->data = NULL;
+ EVP_KDF_free(ctx->meth);
+ OPENSSL_free(ctx);
}
EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src)
diff --git a/crypto/evp/kdf_meth.c b/crypto/evp/kdf_meth.c
index 1caf1c579c..5c2ac46f4e 100644
--- a/crypto/evp/kdf_meth.c
+++ b/crypto/evp/kdf_meth.c
@@ -25,18 +25,20 @@ static int evp_kdf_up_ref(void *vkdf)
return 1;
}
-static void evp_kdf_free(void *vkdf){
+static void evp_kdf_free(void *vkdf)
+{
EVP_KDF *kdf = (EVP_KDF *)vkdf;
int ref = 0;
- if (kdf != NULL) {
- CRYPTO_DOWN_REF(&kdf->refcnt, &ref, kdf->lock);
- if (ref <= 0) {
- ossl_provider_free(kdf->prov);
- CRYPTO_THREAD_lock_free(kdf->lock);
- OPENSSL_free(kdf);
- }
- }
+ if (kdf == NULL)
+ return;
+
+ CRYPTO_DOWN_REF(&kdf->refcnt, &ref, kdf->lock);
+ if (ref > 0)
+ return;
+ ossl_provider_free(kdf->prov);
+ CRYPTO_THREAD_lock_free(kdf->lock);
+ OPENSSL_free(kdf);
}
static void *evp_kdf_new(void)
diff --git a/crypto/evp/kem.c b/crypto/evp/kem.c
index cd8924ef39..227d3c721a 100644
--- a/crypto/evp/kem.c
+++ b/crypto/evp/kem.c
@@ -299,16 +299,17 @@ static void *evp_kem_from_algorithm(int name_id, const OSSL_ALGORITHM *algodef,
void EVP_KEM_free(EVP_KEM *kem)
{
- if (kem != NULL) {
- int i;
-
- CRYPTO_DOWN_REF(&kem->refcnt, &i, kem->lock);
- if (i > 0)
- return;
- ossl_provider_free(kem->prov);
- CRYPTO_THREAD_lock_free(kem->lock);
- OPENSSL_free(kem);
- }
+ int i;
+
+ if (kem == NULL)
+ return;
+
+ CRYPTO_DOWN_REF(&kem->refcnt, &i, kem->lock);
+ if (i > 0)
+ return;
+ ossl_provider_free(kem->prov);
+ CRYPTO_THREAD_lock_free(kem->lock);
+ OPENSSL_free(kem);
}
int EVP_KEM_up_ref(EVP_KEM *kem)
diff --git a/crypto/evp/mac_lib.c b/crypto/evp/mac_lib.c
index e7eea3294b..0784aaddc2 100644
--- a/crypto/evp/mac_lib.c
+++ b/crypto/evp/mac_lib.c
@@ -39,12 +39,12 @@ EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac)
void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx)
{
- if (ctx != NULL) {
- ctx->meth->freectx(ctx->data);
- ctx->data = NULL;
- /* refcnt-- */
- EVP_MAC_free(ctx->meth);
- }
+ if (ctx == NULL)
+ return;
+ ctx->meth->freectx(ctx->data);
+ ctx->data = NULL;
+ /* refcnt-- */
+ EVP_MAC_free(ctx->meth);
OPENSSL_free(ctx);
}
diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c
index 7df984e1bf..0307fb5e33 100644
--- a/crypto/evp/signature.c
+++ b/crypto/evp/signature.c
@@ -275,16 +275,16 @@ static void *evp_signature_from_algorithm(int name_id,
void EVP_SIGNATURE_free(EVP_SIGNATURE *signature)
{
- if (signature != NULL) {
- int i;
-
- CRYPTO_DOWN_REF(&signature->refcnt, &i, signature->lock);
- if (i > 0)
- return;
- ossl_provider_free(signature->prov);
- CRYPTO_THREAD_lock_free(signature->lock);
- OPENSSL_free(signature);
- }
+ int i;
+
+ if (signature == NULL)
+ return;
+ CRYPTO_DOWN_REF(&signature->refcnt, &i, signature->lock);
+ if (i > 0)
+ return;
+ ossl_provider_free(signature->prov);
+ CRYPTO_THREAD_lock_free(signature->lock);
+ OPENSSL_free(signature);
}
int EVP_SIGNATURE_up_ref(EVP_SIGNATURE *signature)