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/evp | |
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/evp')
-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 |
8 files changed, 18 insertions, 34 deletions
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) /* |