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>
This commit is contained in:
Rich Salz 2015-03-28 10:54:15 -04:00
parent 33b188a8e8
commit c5ba2d9904
48 changed files with 90 additions and 165 deletions

View file

@ -384,8 +384,7 @@ int MAIN(int argc, char **argv)
}
r = 1;
mac_end:
if (mac_ctx)
EVP_PKEY_CTX_free(mac_ctx);
EVP_PKEY_CTX_free(mac_ctx);
if (r == 0)
goto end;
}

View file

@ -268,10 +268,8 @@ int MAIN(int argc, char **argv)
ret = 0;
end:
if (pkey)
EVP_PKEY_free(pkey);
if (ctx)
EVP_PKEY_CTX_free(ctx);
EVP_PKEY_free(pkey);
EVP_PKEY_CTX_free(ctx);
BIO_free_all(out);
BIO_free(in);
if (pass)
@ -317,10 +315,8 @@ static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx,
err:
BIO_puts(err, "Error initializing context\n");
ERR_print_errors(err);
if (ctx)
EVP_PKEY_CTX_free(ctx);
if (pkey)
EVP_PKEY_free(pkey);
EVP_PKEY_CTX_free(ctx);
EVP_PKEY_free(pkey);
return 0;
}
@ -375,8 +371,7 @@ int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx,
err:
BIO_printf(err, "Error initializing %s context\n", algname);
ERR_print_errors(err);
if (ctx)
EVP_PKEY_CTX_free(ctx);
EVP_PKEY_CTX_free(ctx);
return 0;
}

View file

@ -672,8 +672,7 @@ int MAIN(int argc, char **argv)
CRYPTO_push_info("process -export_cert: freeing");
# endif
if (key)
EVP_PKEY_free(key);
EVP_PKEY_free(key);
if (certs)
sk_X509_pop_free(certs, X509_free);
if (ucert)

View file

@ -332,8 +332,7 @@ int MAIN(int argc, char **argv)
BIO_write(out, buf_out, buf_outlen);
end:
if (ctx)
EVP_PKEY_CTX_free(ctx);
EVP_PKEY_CTX_free(ctx);
BIO_free(in);
BIO_free_all(out);
if (buf_in)

View file

@ -874,9 +874,9 @@ int MAIN(int argc, char **argv)
if (pkey == NULL) {
pkey = X509_REQ_get_pubkey(req);
tmp = 1;
if (pkey == NULL)
goto end;
tmp = 1;
}
i = X509_REQ_verify(req, pkey);
@ -1013,8 +1013,7 @@ int MAIN(int argc, char **argv)
BIO_free(in);
BIO_free_all(out);
EVP_PKEY_free(pkey);
if (genctx)
EVP_PKEY_CTX_free(genctx);
EVP_PKEY_CTX_free(genctx);
if (pkeyopts)
sk_OPENSSL_STRING_free(pkeyopts);
if (sigopts)

View file

@ -1242,8 +1242,7 @@ void ssl_excert_free(SSL_EXCERT *exc)
while (exc) {
if (exc->cert)
X509_free(exc->cert);
if (exc->key)
EVP_PKEY_free(exc->key);
EVP_PKEY_free(exc->key);
if (exc->chain)
sk_X509_pop_free(exc->chain, X509_free);
curr = exc;

View file

@ -2030,8 +2030,7 @@ int MAIN(int argc, char **argv)
X509_free(cert);
if (crls)
sk_X509_CRL_pop_free(crls, X509_CRL_free);
if (key)
EVP_PKEY_free(key);
EVP_PKEY_free(key);
if (chain)
sk_X509_pop_free(chain, X509_free);
if (pass)

View file

@ -2011,10 +2011,8 @@ int MAIN(int argc, char *argv[])
sk_X509_CRL_pop_free(crls, X509_CRL_free);
if (s_dcert)
X509_free(s_dcert);
if (s_key)
EVP_PKEY_free(s_key);
if (s_dkey)
EVP_PKEY_free(s_dkey);
EVP_PKEY_free(s_key);
EVP_PKEY_free(s_dkey);
if (s_chain)
sk_X509_pop_free(s_chain, X509_free);
if (s_dchain)
@ -2037,8 +2035,7 @@ int MAIN(int argc, char *argv[])
SSL_CTX_free(ctx2);
if (s_cert2)
X509_free(s_cert2);
if (s_key2)
EVP_PKEY_free(s_key2);
EVP_PKEY_free(s_key2);
BIO_free(serverinfo_in);
# ifndef OPENSSL_NO_NEXTPROTONEG
if (next_proto.data)

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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) {

View file

@ -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);

View file

@ -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;
}

View file

@ -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;

View file

@ -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 */

View file

@ -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;
}

View file

@ -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)
/*

View file

@ -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;

View file

@ -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;
}

View file

@ -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,

View file

@ -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;

View file

@ -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);

View file

@ -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;
}

View file

@ -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)
/*

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -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

View file

@ -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,

View file

@ -72,8 +72,7 @@ int main(int argc, char **argv)
CMS_ContentInfo_free(cms);
if (rcert)
X509_free(rcert);
if (rkey)
EVP_PKEY_free(rkey);
EVP_PKEY_free(rkey);
BIO_free(in);
BIO_free(out);

View file

@ -63,8 +63,7 @@ int main(int argc, char **argv)
CMS_ContentInfo_free(cms);
if (rcert)
X509_free(rcert);
if (rkey)
EVP_PKEY_free(rkey);
EVP_PKEY_free(rkey);
BIO_free(in);
BIO_free(out);

View file

@ -73,8 +73,7 @@ int main(int argc, char **argv)
CMS_ContentInfo_free(cms);
if (scert)
X509_free(scert);
if (skey)
EVP_PKEY_free(skey);
EVP_PKEY_free(skey);
BIO_free(in);
BIO_free(out);

View file

@ -82,13 +82,11 @@ int main(int argc, char **argv)
if (scert)
X509_free(scert);
if (skey)
EVP_PKEY_free(skey);
EVP_PKEY_free(skey);
if (scert2)
X509_free(scert2);
if (skey)
EVP_PKEY_free(skey2);
EVP_PKEY_free(skey2);
BIO_free(in);
BIO_free(out);

View file

@ -63,8 +63,7 @@ int main(int argc, char **argv)
PKCS7_free(p7);
if (rcert)
X509_free(rcert);
if (rkey)
EVP_PKEY_free(rkey);
EVP_PKEY_free(rkey);
BIO_free(in);
BIO_free(out);

View file

@ -73,8 +73,7 @@ int main(int argc, char **argv)
PKCS7_free(p7);
if (scert)
X509_free(scert);
if (skey)
EVP_PKEY_free(skey);
EVP_PKEY_free(skey);
BIO_free(in);
BIO_free(out);

View file

@ -82,13 +82,11 @@ int main(int argc, char **argv)
if (scert)
X509_free(scert);
if (skey)
EVP_PKEY_free(skey);
EVP_PKEY_free(skey);
if (scert2)
X509_free(scert2);
if (skey)
EVP_PKEY_free(skey2);
EVP_PKEY_free(skey2);
BIO_free(in);
BIO_free(out);

View file

@ -26,6 +26,7 @@ during parameter generation of key genration for some algorithms.
EVP_PKEY_CTX_dup() duplicates the context B<ctx>.
EVP_PKEY_CTX_free() frees up the context B<ctx>.
If B<ctx> is NULL, nothing is done.
=head1 NOTES

View file

@ -18,6 +18,7 @@ The EVP_PKEY_new() function allocates an empty B<EVP_PKEY>
structure which is used by OpenSSL to store private keys.
EVP_PKEY_free() frees up the private key B<key>.
If B<key> is NULL, nothing is done.
=head1 NOTES

View file

@ -189,7 +189,7 @@ int pkey_GOST01cp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
}
ASN1_OBJECT_free(gkt->key_agreement_info->cipher);
gkt->key_agreement_info->cipher = OBJ_nid2obj(param->nid);
if (key_is_ephemeral && sec_key)
if (key_is_ephemeral)
EVP_PKEY_free(sec_key);
if (!key_is_ephemeral) {
/* Set control "public key from client certificate used" */
@ -204,7 +204,7 @@ int pkey_GOST01cp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
GOST_KEY_TRANSPORT_free(gkt);
return ret;
err:
if (key_is_ephemeral && sec_key)
if (key_is_ephemeral)
EVP_PKEY_free(sec_key);
GOST_KEY_TRANSPORT_free(gkt);
return -1;
@ -284,8 +284,7 @@ int pkey_GOST01cp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
ret = 1;
err:
if (eph_key)
EVP_PKEY_free(eph_key);
EVP_PKEY_free(eph_key);
if (gkt)
GOST_KEY_TRANSPORT_free(gkt);
return ret;

View file

@ -887,8 +887,7 @@ static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id,
return res;
err:
if (res)
EVP_PKEY_free(res);
EVP_PKEY_free(res);
return NULL;
}

View file

@ -2869,8 +2869,7 @@ int ssl3_get_client_key_exchange(SSL *s)
EVP_PKEY_CTX_free(pkey_ctx);
if (ret)
return ret;
else
goto err;
goto err;
} else {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, SSL_R_UNKNOWN_CIPHER_TYPE);

View file

@ -402,10 +402,8 @@ void ssl_cert_clear_certs(CERT *c)
X509_free(cpk->x509);
cpk->x509 = NULL;
}
if (cpk->privatekey) {
EVP_PKEY_free(cpk->privatekey);
cpk->privatekey = NULL;
}
EVP_PKEY_free(cpk->privatekey);
cpk->privatekey = NULL;
if (cpk->chain) {
sk_X509_pop_free(cpk->chain, X509_free);
cpk->chain = NULL;