diff options
author | Rich Salz <rsalz@openssl.org> | 2015-03-28 10:54:15 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-03-28 10:54:15 -0400 |
commit | c5ba2d990420e1778ca4a90bf882e0f806404af0 (patch) | |
tree | 61641d19bea624b7fa523162f0ebb0d5e2fccf55 /crypto | |
parent | 33b188a8e82df57208ec8263c263f8b6f47e8255 (diff) |
free NULL cleanup
EVP_.*free; this gets:
EVP_CIPHER_CTX_free EVP_PKEY_CTX_free EVP_PKEY_asn1_free
EVP_PKEY_asn1_set_free EVP_PKEY_free EVP_PKEY_free_it
EVP_PKEY_meth_free; and also EVP_CIPHER_CTX_cleanup
Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asn1/d2i_pr.c | 2 | ||||
-rw-r--r-- | crypto/asn1/d2i_pu.c | 2 | ||||
-rw-r--r-- | crypto/asn1/x_pkey.c | 3 | ||||
-rw-r--r-- | crypto/asn1/x_pubkey.c | 3 | ||||
-rw-r--r-- | crypto/cms/cms_asn1.c | 15 | ||||
-rw-r--r-- | crypto/cms/cms_env.c | 9 | ||||
-rw-r--r-- | crypto/cms/cms_kari.c | 8 | ||||
-rw-r--r-- | crypto/cms/cms_sd.c | 9 | ||||
-rw-r--r-- | crypto/dh/dh_ameth.c | 6 | ||||
-rw-r--r-- | crypto/ec/ec_ameth.c | 3 | ||||
-rw-r--r-- | crypto/evp/digest.c | 3 | ||||
-rw-r--r-- | crypto/evp/evp_enc.c | 7 | ||||
-rw-r--r-- | crypto/evp/evp_extra_test.c | 20 | ||||
-rw-r--r-- | crypto/evp/evp_test.c | 9 | ||||
-rw-r--r-- | crypto/evp/p_lib.c | 1 | ||||
-rw-r--r-- | crypto/evp/pmeth_fn.c | 3 | ||||
-rw-r--r-- | crypto/evp/pmeth_gn.c | 3 | ||||
-rw-r--r-- | crypto/evp/pmeth_lib.c | 6 | ||||
-rw-r--r-- | crypto/pem/pem_pk8.c | 3 | ||||
-rw-r--r-- | crypto/pem/pem_pkey.c | 9 | ||||
-rw-r--r-- | crypto/pem/pvkfmt.c | 6 | ||||
-rw-r--r-- | crypto/pkcs12/p12_kiss.c | 2 | ||||
-rw-r--r-- | crypto/pkcs7/pk7_doit.c | 13 | ||||
-rw-r--r-- | crypto/pkcs7/pk7_lib.c | 3 | ||||
-rw-r--r-- | crypto/ts/ts_rsp_sign.c | 3 | ||||
-rw-r--r-- | crypto/x509/x509_cmp.c | 6 | ||||
-rw-r--r-- | crypto/x509/x509_vfy.c | 6 |
27 files changed, 57 insertions, 106 deletions
diff --git a/crypto/asn1/d2i_pr.c b/crypto/asn1/d2i_pr.c index 5f1a96d808..793532f493 100644 --- a/crypto/asn1/d2i_pr.c +++ b/crypto/asn1/d2i_pr.c @@ -113,7 +113,7 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, (*a) = ret; return (ret); err: - if ((ret != NULL) && ((a == NULL) || (*a != ret))) + if (a == NULL || *a != ret) EVP_PKEY_free(ret); return (NULL); } diff --git a/crypto/asn1/d2i_pu.c b/crypto/asn1/d2i_pu.c index 33542dd122..189cfddf1e 100644 --- a/crypto/asn1/d2i_pu.c +++ b/crypto/asn1/d2i_pu.c @@ -130,7 +130,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, (*a) = ret; return (ret); err: - if ((ret != NULL) && ((a == NULL) || (*a != ret))) + if (a == NULL || *a != ret) EVP_PKEY_free(ret); return (NULL); } diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c index f4396e7d17..f24c0ce914 100644 --- a/crypto/asn1/x_pkey.c +++ b/crypto/asn1/x_pkey.c @@ -144,8 +144,7 @@ void X509_PKEY_free(X509_PKEY *x) if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); ASN1_OCTET_STRING_free(x->enc_pkey); - if (x->dec_pkey != NULL) - EVP_PKEY_free(x->dec_pkey); + EVP_PKEY_free(x->dec_pkey); if ((x->key_data != NULL) && (x->key_free)) OPENSSL_free(x->key_data); OPENSSL_free(x); diff --git a/crypto/asn1/x_pubkey.c b/crypto/asn1/x_pubkey.c index cefaf3ac40..3c72997f03 100644 --- a/crypto/asn1/x_pubkey.c +++ b/crypto/asn1/x_pubkey.c @@ -174,8 +174,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) return ret; error: - if (ret != NULL) - EVP_PKEY_free(ret); + EVP_PKEY_free(ret); return (NULL); } diff --git a/crypto/cms/cms_asn1.c b/crypto/cms/cms_asn1.c index 9a71919c8f..03de7af204 100644 --- a/crypto/cms/cms_asn1.c +++ b/crypto/cms/cms_asn1.c @@ -93,8 +93,7 @@ static int cms_si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, { if (operation == ASN1_OP_FREE_POST) { CMS_SignerInfo *si = (CMS_SignerInfo *)*pval; - if (si->pkey) - EVP_PKEY_free(si->pkey); + EVP_PKEY_free(si->pkey); if (si->signer) X509_free(si->signer); if (si->pctx) @@ -171,8 +170,7 @@ static int cms_rek_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, { CMS_RecipientEncryptedKey *rek = (CMS_RecipientEncryptedKey *)*pval; if (operation == ASN1_OP_FREE_POST) { - if (rek->pkey) - EVP_PKEY_free(rek->pkey); + EVP_PKEY_free(rek->pkey); } return 1; } @@ -202,8 +200,7 @@ static int cms_kari_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, EVP_CIPHER_CTX_set_flags(&kari->ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW); kari->pctx = NULL; } else if (operation == ASN1_OP_FREE_POST) { - if (kari->pctx) - EVP_PKEY_CTX_free(kari->pctx); + EVP_PKEY_CTX_free(kari->pctx); EVP_CIPHER_CTX_cleanup(&kari->ctx); } return 1; @@ -250,12 +247,10 @@ static int cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, CMS_RecipientInfo *ri = (CMS_RecipientInfo *)*pval; if (ri->type == CMS_RECIPINFO_TRANS) { CMS_KeyTransRecipientInfo *ktri = ri->d.ktri; - if (ktri->pkey) - EVP_PKEY_free(ktri->pkey); + EVP_PKEY_free(ktri->pkey); if (ktri->recip) X509_free(ktri->recip); - if (ktri->pctx) - EVP_PKEY_CTX_free(ktri->pctx); + EVP_PKEY_CTX_free(ktri->pctx); } else if (ri->type == CMS_RECIPINFO_KEK) { CMS_KEKRecipientInfo *kekri = ri->d.kekri; if (kekri->key) { diff --git a/crypto/cms/cms_env.c b/crypto/cms/cms_env.c index d1252f8d87..3b4b930136 100644 --- a/crypto/cms/cms_env.c +++ b/crypto/cms/cms_env.c @@ -279,8 +279,7 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, err: if (ri) M_ASN1_free_of(ri, CMS_RecipientInfo); - if (pk) - EVP_PKEY_free(pk); + EVP_PKEY_free(pk); return NULL; } @@ -476,10 +475,8 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, ec->keylen = eklen; err: - if (ktri->pctx) { - EVP_PKEY_CTX_free(ktri->pctx); - ktri->pctx = NULL; - } + EVP_PKEY_CTX_free(ktri->pctx); + ktri->pctx = NULL; if (!ret && ek) OPENSSL_free(ek); diff --git a/crypto/cms/cms_kari.c b/crypto/cms/cms_kari.c index 196b5c60f1..5aaba59c11 100644 --- a/crypto/cms/cms_kari.c +++ b/crypto/cms/cms_kari.c @@ -218,8 +218,7 @@ int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk) kari->pctx = pctx; return 1; err: - if (pctx) - EVP_PKEY_CTX_free(pctx); + EVP_PKEY_CTX_free(pctx); return 0; } @@ -331,10 +330,9 @@ static int cms_kari_create_ephemeral_key(CMS_KeyAgreeRecipientInfo *kari, kari->pctx = pctx; rv = 1; err: - if (!rv && pctx) + if (!rv) EVP_PKEY_CTX_free(pctx); - if (ekey) - EVP_PKEY_free(ekey); + EVP_PKEY_free(ekey); return rv; } diff --git a/crypto/cms/cms_sd.c b/crypto/cms/cms_sd.c index c45d30eac1..71c234cb39 100644 --- a/crypto/cms/cms_sd.c +++ b/crypto/cms/cms_sd.c @@ -487,8 +487,7 @@ void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer) { if (signer) { CRYPTO_add(&signer->references, 1, CRYPTO_LOCK_X509); - if (si->pkey) - EVP_PKEY_free(si->pkey); + EVP_PKEY_free(si->pkey); si->pkey = X509_get_pubkey(signer); } if (si->signer) @@ -651,8 +650,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms, err: EVP_MD_CTX_cleanup(&mctx); - if (pctx) - EVP_PKEY_CTX_free(pctx); + EVP_PKEY_CTX_free(pctx); return r; } @@ -875,8 +873,7 @@ int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain) } err: - if (pkctx) - EVP_PKEY_CTX_free(pkctx); + EVP_PKEY_CTX_free(pkctx); EVP_MD_CTX_cleanup(&mctx); return r; diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index c71538fa15..cfa2e2dbec 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -708,8 +708,7 @@ static int dh_cms_set_peerkey(EVP_PKEY_CTX *pctx, err: if (public_key) ASN1_INTEGER_free(public_key); - if (pkpeer) - EVP_PKEY_free(pkpeer); + EVP_PKEY_free(pkpeer); DH_free(dhpeer); return rv; } @@ -849,8 +848,7 @@ static int dh_cms_encrypt(CMS_RecipientInfo *ri) X509_ALGOR_get0(&aoid, NULL, NULL, talg); /* Is everything uninitialised? */ if (aoid == OBJ_nid2obj(NID_undef)) { - ASN1_INTEGER *pubk; - pubk = BN_to_ASN1_INTEGER(pkey->pkey.dh->pub_key, NULL); + ASN1_INTEGER *pubk = BN_to_ASN1_INTEGER(pkey->pkey.dh->pub_key, NULL); if (!pubk) goto err; /* Set the key */ diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c index 4be85a9e87..65c3d569ab 100644 --- a/crypto/ec/ec_ameth.c +++ b/crypto/ec/ec_ameth.c @@ -704,8 +704,7 @@ static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx, rv = 1; err: EC_KEY_free(ecpeer); - if (pkpeer) - EVP_PKEY_free(pkpeer); + EVP_PKEY_free(pkpeer); return rv; } diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 48c7b00b4c..ce95350bfd 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -352,8 +352,7 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) OPENSSL_cleanse(ctx->md_data, ctx->digest->ctx_size); OPENSSL_free(ctx->md_data); } - if (ctx->pctx) - EVP_PKEY_CTX_free(ctx->pctx); + EVP_PKEY_CTX_free(ctx->pctx); #ifndef OPENSSL_NO_ENGINE if (ctx->engine) /* diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 3d40b0481b..3468b6b3fb 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -522,14 +522,15 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) { - if (ctx) { - EVP_CIPHER_CTX_cleanup(ctx); + EVP_CIPHER_CTX_cleanup(ctx); + if (ctx) OPENSSL_free(ctx); - } } int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) { + if (!c) + return 0; if (c->cipher != NULL) { if (c->cipher->cleanup && !c->cipher->cleanup(c)) return 0; diff --git a/crypto/evp/evp_extra_test.c b/crypto/evp/evp_extra_test.c index c474134a2d..567ed0f5f9 100644 --- a/crypto/evp/evp_extra_test.c +++ b/crypto/evp/evp_extra_test.c @@ -265,9 +265,7 @@ static EVP_PKEY *load_example_rsa_key(void) pkey = NULL; out: - if (pkey) { - EVP_PKEY_free(pkey); - } + EVP_PKEY_free(pkey); RSA_free(rsa); return ret; @@ -321,9 +319,7 @@ static int test_EVP_DigestSignInit(void) EVP_MD_CTX_cleanup(&md_ctx); EVP_MD_CTX_cleanup(&md_ctx_verify); - if (pkey) { - EVP_PKEY_free(pkey); - } + EVP_PKEY_free(pkey); if (sig) { OPENSSL_free(sig); } @@ -354,9 +350,7 @@ static int test_EVP_DigestVerifyInit(void) } EVP_MD_CTX_cleanup(&md_ctx); - if (pkey) { - EVP_PKEY_free(pkey); - } + EVP_PKEY_free(pkey); return ret; } @@ -387,9 +381,7 @@ static int test_d2i_AutoPrivateKey(const unsigned char *input, ERR_print_errors_fp(stderr); } - if (pkey != NULL) { - EVP_PKEY_free(pkey); - } + EVP_PKEY_free(pkey); return ret; } @@ -422,9 +414,7 @@ static int test_EVP_PKCS82PKEY(void) PKCS8_PRIV_KEY_INFO_free(p8inf); } - if (pkey != NULL) { - EVP_PKEY_free(pkey); - } + EVP_PKEY_free(pkey); return ret; } diff --git a/crypto/evp/evp_test.c b/crypto/evp/evp_test.c index 152465878e..68d5bde300 100644 --- a/crypto/evp/evp_test.c +++ b/crypto/evp/evp_test.c @@ -1051,10 +1051,8 @@ static int mac_test_run(struct evp_test *t) EVP_MD_CTX_destroy(mctx); if (mac) OPENSSL_free(mac); - if (genctx) - EVP_PKEY_CTX_free(genctx); - if (key) - EVP_PKEY_free(key); + EVP_PKEY_CTX_free(genctx); + EVP_PKEY_free(key); t->err = err; return 1; } @@ -1139,8 +1137,7 @@ static void pkey_test_cleanup(struct evp_test *t) OPENSSL_free(kdata->input); if (kdata->output) OPENSSL_free(kdata->output); - if (kdata->ctx) - EVP_PKEY_CTX_free(kdata->ctx); + EVP_PKEY_CTX_free(kdata->ctx); } static int pkey_test_parse(struct evp_test *t, diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 604faf2c6b..a96fae6125 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -409,6 +409,7 @@ void EVP_PKEY_free(EVP_PKEY *x) static void EVP_PKEY_free_it(EVP_PKEY *x) { + /* internal function; x is never NULL */ if (x->ameth && x->ameth->pkey_free) { x->ameth->pkey_free(x); x->pkey.ptr = NULL; diff --git a/crypto/evp/pmeth_fn.c b/crypto/evp/pmeth_fn.c index 829b5f0409..abf216082d 100644 --- a/crypto/evp/pmeth_fn.c +++ b/crypto/evp/pmeth_fn.c @@ -315,8 +315,7 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) return -1; } - if (ctx->peerkey) - EVP_PKEY_free(ctx->peerkey); + EVP_PKEY_free(ctx->peerkey); ctx->peerkey = peer; ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer); diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index a5ae484849..78467c98f7 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -207,7 +207,6 @@ EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, if (EVP_PKEY_keygen(mac_ctx, &mac_key) <= 0) goto merr; merr: - if (mac_ctx) - EVP_PKEY_CTX_free(mac_ctx); + EVP_PKEY_CTX_free(mac_ctx); return mac_key; } diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 9183e405ea..b20a902ef7 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -363,10 +363,8 @@ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) return; if (ctx->pmeth && ctx->pmeth->cleanup) ctx->pmeth->cleanup(ctx); - if (ctx->pkey) - EVP_PKEY_free(ctx->pkey); - if (ctx->peerkey) - EVP_PKEY_free(ctx->peerkey); + EVP_PKEY_free(ctx->pkey); + EVP_PKEY_free(ctx->peerkey); #ifndef OPENSSL_NO_ENGINE if (ctx->engine) /* diff --git a/crypto/pem/pem_pk8.c b/crypto/pem/pem_pk8.c index 0d76026155..529d077a9a 100644 --- a/crypto/pem/pem_pk8.c +++ b/crypto/pem/pem_pk8.c @@ -183,8 +183,7 @@ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, if (!ret) return NULL; if (x) { - if (*x) - EVP_PKEY_free(*x); + EVP_PKEY_free(*x); *x = ret; } return ret; diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index fd7e8b0376..80c316ed38 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -96,8 +96,7 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, goto p8err; ret = EVP_PKCS82PKEY(p8inf); if (x) { - if (*x) - EVP_PKEY_free((EVP_PKEY *)*x); + EVP_PKEY_free((EVP_PKEY *)*x); *x = ret; } PKCS8_PRIV_KEY_INFO_free(p8inf); @@ -124,8 +123,7 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, goto p8err; ret = EVP_PKCS82PKEY(p8inf); if (x) { - if (*x) - EVP_PKEY_free((EVP_PKEY *)*x); + EVP_PKEY_free((EVP_PKEY *)*x); *x = ret; } PKCS8_PRIV_KEY_INFO_free(p8inf); @@ -186,8 +184,7 @@ EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x) goto err; } if (x) { - if (*x) - EVP_PKEY_free((EVP_PKEY *)*x); + EVP_PKEY_free((EVP_PKEY *)*x); *x = ret; } } diff --git a/crypto/pem/pvkfmt.c b/crypto/pem/pvkfmt.c index 0f2390d3b4..14ddb33a26 100644 --- a/crypto/pem/pvkfmt.c +++ b/crypto/pem/pvkfmt.c @@ -336,8 +336,7 @@ static EVP_PKEY *b2i_dss(const unsigned char **in, unsigned int length, memerr: PEMerr(PEM_F_B2I_DSS, ERR_R_MALLOC_FAILURE); DSA_free(dsa); - if (ret) - EVP_PKEY_free(ret); + EVP_PKEY_free(ret); if (ctx) BN_CTX_free(ctx); return NULL; @@ -385,8 +384,7 @@ static EVP_PKEY *b2i_rsa(const unsigned char **in, unsigned int length, memerr: PEMerr(PEM_F_B2I_RSA, ERR_R_MALLOC_FAILURE); RSA_free(rsa); - if (ret) - EVP_PKEY_free(ret); + EVP_PKEY_free(ret); return NULL; } diff --git a/crypto/pkcs12/p12_kiss.c b/crypto/pkcs12/p12_kiss.c index 4fd8b8c229..fcfa986824 100644 --- a/crypto/pkcs12/p12_kiss.c +++ b/crypto/pkcs12/p12_kiss.c @@ -161,7 +161,7 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, err: - if (pkey && *pkey) + if (pkey) EVP_PKEY_free(*pkey); if (cert && *cert) X509_free(*cert); diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c index b7c66a3160..639e217425 100644 --- a/crypto/pkcs7/pk7_doit.c +++ b/crypto/pkcs7/pk7_doit.c @@ -179,10 +179,8 @@ static int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri, ret = 1; err: - if (pkey) - EVP_PKEY_free(pkey); - if (pctx) - EVP_PKEY_CTX_free(pctx); + EVP_PKEY_free(pkey); + EVP_PKEY_CTX_free(pctx); if (ek) OPENSSL_free(ek); return ret; @@ -240,8 +238,7 @@ static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen, *peklen = eklen; err: - if (pctx) - EVP_PKEY_CTX_free(pctx); + EVP_PKEY_CTX_free(pctx); if (!ret && ek) OPENSSL_free(ek); @@ -1077,8 +1074,8 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, PKCS7_R_SIGNATURE_FAILURE); ret = -1; goto err; - } else - ret = 1; + } + ret = 1; err: EVP_MD_CTX_cleanup(&mdc_tmp); return (ret); diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c index 6409d2867c..956f3f22e7 100644 --- a/crypto/pkcs7/pk7_lib.c +++ b/crypto/pkcs7/pk7_lib.c @@ -556,8 +556,7 @@ int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509) return 1; err: - if (pkey) - EVP_PKEY_free(pkey); + EVP_PKEY_free(pkey); return 0; } diff --git a/crypto/ts/ts_rsp_sign.c b/crypto/ts/ts_rsp_sign.c index b510cebde3..037ab645a2 100644 --- a/crypto/ts/ts_rsp_sign.c +++ b/crypto/ts/ts_rsp_sign.c @@ -216,8 +216,7 @@ int TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer) int TS_RESP_CTX_set_signer_key(TS_RESP_CTX *ctx, EVP_PKEY *key) { - if (ctx->signer_key) - EVP_PKEY_free(ctx->signer_key); + EVP_PKEY_free(ctx->signer_key); ctx->signer_key = key; CRYPTO_add(&ctx->signer_key->references, +1, CRYPTO_LOCK_EVP_PKEY); diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c index 51c47cc781..c7b0fe1e29 100644 --- a/crypto/x509/x509_cmp.c +++ b/crypto/x509/x509_cmp.c @@ -342,8 +342,7 @@ int X509_check_private_key(X509 *x, EVP_PKEY *k) case -2: X509err(X509_F_X509_CHECK_PRIVATE_KEY, X509_R_UNKNOWN_KEY_TYPE); } - if (xk) - EVP_PKEY_free(xk); + EVP_PKEY_free(xk); if (ret > 0) return 1; return 0; @@ -436,8 +435,7 @@ int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain, /* Final check: root CA signature */ rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags); end: - if (pk) - EVP_PKEY_free(pk); + EVP_PKEY_free(pk); if (rv != X509_V_OK) { /* Invalid signature or LOS errors are for previous cert */ if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index 61f02b58a6..9cf39db269 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -1933,10 +1933,8 @@ int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain) } if (!EVP_PKEY_missing_parameters(ktmp)) break; - else { - EVP_PKEY_free(ktmp); - ktmp = NULL; - } + EVP_PKEY_free(ktmp); + ktmp = NULL; } if (ktmp == NULL) { X509err(X509_F_X509_GET_PUBKEY_PARAMETERS, |