From 23a1d5e97cd543d2b8e1b01dbf0f619b2e5ce540 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Thu, 30 Apr 2015 21:37:06 -0400 Subject: free NULL cleanup 7 This gets BN_.*free: BN_BLINDING_free BN_CTX_free BN_FLG_FREE BN_GENCB_free BN_MONT_CTX_free BN_RECP_CTX_free BN_clear_free BN_free BUF_MEM_free Also fix a call to DSA_SIG_free to ccgost engine and remove some #ifdef'd dead code in engines/e_ubsec. Reviewed-by: Richard Levitte --- crypto/dh/dh_ameth.c | 3 +-- crypto/dh/dh_check.c | 3 +-- crypto/dh/dh_key.c | 13 +++++-------- crypto/dh/dh_lib.c | 21 +++++++-------------- crypto/dh/dh_pmeth.c | 9 +++------ 5 files changed, 17 insertions(+), 32 deletions(-) (limited to 'crypto/dh') diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index f3abe0774f..6a4223c167 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -463,8 +463,7 @@ static int int_dh_bn_cpy(BIGNUM **dst, const BIGNUM *src) return 0; } else a = NULL; - if (*dst) - BN_free(*dst); + BN_free(*dst); *dst = a; return 1; } diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c index 7a8e063fc8..b8b3890d9e 100644 --- a/crypto/dh/dh_check.c +++ b/crypto/dh/dh_check.c @@ -159,7 +159,6 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret) ok = 1; err: - if (q != NULL) - BN_free(q); + BN_free(q); return (ok); } diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 9e2c8b26e6..e2f48b142d 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -172,12 +172,10 @@ static int generate_key(DH *dh) prk = priv_key; if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) { - if (local_prk) - BN_free(local_prk); + BN_free(local_prk); goto err; } - if (local_prk) - BN_free(local_prk); + BN_free(local_prk); } dh->pub_key = pub_key; @@ -187,9 +185,9 @@ static int generate_key(DH *dh) if (ok != 1) DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB); - if ((pub_key != NULL) && (dh->pub_key == NULL)) + if (pub_key != dh->pub_key) BN_free(pub_key); - if ((priv_key != NULL) && (dh->priv_key == NULL)) + if (priv_key != dh->priv_key) BN_free(priv_key); BN_CTX_free(ctx); return (ok); @@ -273,7 +271,6 @@ static int dh_init(DH *dh) static int dh_finish(DH *dh) { - if (dh->method_mont_p) - BN_MONT_CTX_free(dh->method_mont_p); + BN_MONT_CTX_free(dh->method_mont_p); return (1); } diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c index 68a54a6fd2..74bad4dfcf 100644 --- a/crypto/dh/dh_lib.c +++ b/crypto/dh/dh_lib.c @@ -194,22 +194,15 @@ void DH_free(DH *r) CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data); - if (r->p != NULL) - BN_clear_free(r->p); - if (r->g != NULL) - BN_clear_free(r->g); - if (r->q != NULL) - BN_clear_free(r->q); - if (r->j != NULL) - BN_clear_free(r->j); + BN_clear_free(r->p); + BN_clear_free(r->g); + BN_clear_free(r->q); + BN_clear_free(r->j); if (r->seed) OPENSSL_free(r->seed); - if (r->counter != NULL) - BN_clear_free(r->counter); - if (r->pub_key != NULL) - BN_clear_free(r->pub_key); - if (r->priv_key != NULL) - BN_clear_free(r->priv_key); + BN_clear_free(r->counter); + BN_clear_free(r->pub_key); + BN_clear_free(r->priv_key); OPENSSL_free(r); } diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index e3ebc0201d..069b855aa0 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -383,8 +383,7 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) if (dctx->use_dsa) { DSA *dsa_dh; dsa_dh = dsa_dh_generate(dctx, pcb); - if (pcb) - BN_GENCB_free(pcb); + BN_GENCB_free(pcb); if (!dsa_dh) return 0; dh = DSA_dup_DH(dsa_dh); @@ -397,14 +396,12 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) #endif dh = DH_new(); if (!dh) { - if (pcb) - BN_GENCB_free(pcb); + BN_GENCB_free(pcb); return 0; } ret = DH_generate_parameters_ex(dh, dctx->prime_len, dctx->generator, pcb); - if (pcb) - BN_GENCB_free(pcb); + BN_GENCB_free(pcb); if (ret) EVP_PKEY_assign_DH(pkey, dh); else -- cgit v1.2.3