diff options
author | David Benjamin <davidben@chromium.org> | 2015-04-22 22:49:27 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-05-05 02:12:04 +0300 |
commit | cca4ba7611ecc6761e2178f39cc9a68e7f5a4911 (patch) | |
tree | 1cfdb2c7e97e0a0d2e055e7fb79ebd99618b8006 /crypto/evp | |
parent | cfaf7ff9bf877239f17c805af6a3d7daae48e0a2 (diff) |
Remove unnecessary NULL checks, part 3.
Finish up the e's.
Change-Id: Iabb8da000fbca6efee541edb469b90896f60d54b
Reviewed-on: https://boringssl-review.googlesource.com/4516
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/asn1.c | 2 | ||||
-rw-r--r-- | crypto/evp/evp_ctx.c | 16 | ||||
-rw-r--r-- | crypto/evp/p_dsa_asn1.c | 53 | ||||
-rw-r--r-- | crypto/evp/p_ec.c | 8 | ||||
-rw-r--r-- | crypto/evp/p_ec_asn1.c | 16 | ||||
-rw-r--r-- | crypto/evp/p_rsa.c | 20 | ||||
-rw-r--r-- | crypto/evp/p_rsa_asn1.c | 20 |
7 files changed, 35 insertions, 100 deletions
diff --git a/crypto/evp/asn1.c b/crypto/evp/asn1.c index 27ae017c..3df9f52b 100644 --- a/crypto/evp/asn1.c +++ b/crypto/evp/asn1.c @@ -105,7 +105,7 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out, const uint8_t **inp, return ret; err: - if (ret != NULL && (out == NULL || *out != ret)) { + if (out == NULL || *out != ret) { EVP_PKEY_free(ret); } return NULL; diff --git a/crypto/evp/evp_ctx.c b/crypto/evp/evp_ctx.c index e94ca1c2..4d927ff1 100644 --- a/crypto/evp/evp_ctx.c +++ b/crypto/evp/evp_ctx.c @@ -125,9 +125,7 @@ static EVP_PKEY_CTX *evp_pkey_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) { if (pmeth->init) { if (pmeth->init(ret) <= 0) { - if (pkey) { - EVP_PKEY_free(ret->pkey); - } + EVP_PKEY_free(ret->pkey); OPENSSL_free(ret); return NULL; } @@ -151,12 +149,8 @@ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) { 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); OPENSSL_free(ctx); } @@ -427,9 +421,7 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) { return 0; } - 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/p_dsa_asn1.c b/crypto/evp/p_dsa_asn1.c index fce644b4..0ac7da77 100644 --- a/crypto/evp/p_dsa_asn1.c +++ b/crypto/evp/p_dsa_asn1.c @@ -122,12 +122,8 @@ static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) { return 1; err: - if (public_key) { - ASN1_INTEGER_free(public_key); - } - if (dsa) { - DSA_free(dsa); - } + ASN1_INTEGER_free(public_key); + DSA_free(dsa); return 0; } @@ -153,12 +149,8 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) { } err: - if (penc) { - OPENSSL_free(penc); - } - if (pval) { - ASN1_STRING_free(pval); - } + OPENSSL_free(penc); + ASN1_STRING_free(pval); return 0; } @@ -266,11 +258,8 @@ static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) { EVP_PKEY_assign_DSA(pkey, dsa); BN_CTX_free(ctx); - if (ndsa) { - sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); - } else { - ASN1_INTEGER_free(privkey); - } + sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); + ASN1_INTEGER_free(privkey); return 1; @@ -279,9 +268,7 @@ decerr: dsaerr: BN_CTX_free(ctx); - if (privkey) { - ASN1_INTEGER_free(privkey); - } + ASN1_INTEGER_free(privkey); sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); DSA_free(dsa); return 0; @@ -331,15 +318,9 @@ static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) { return 1; err: - if (dp != NULL) { - OPENSSL_free(dp); - } - if (params != NULL) { - ASN1_STRING_free(params); - } - if (prkey != NULL) { - ASN1_INTEGER_free(prkey); - } + OPENSSL_free(dp); + ASN1_STRING_free(params); + ASN1_INTEGER_free(prkey); return 0; } @@ -367,9 +348,7 @@ static int dup_bn_into(BIGNUM **out, BIGNUM *src) { if (a == NULL) { return 0; } - if (*out != NULL) { - BN_free(*out); - } + BN_free(*out); *out = a; return 1; @@ -463,10 +442,8 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) { ret = 1; err: - if (m != NULL) { - OPENSSL_free(m); - } - return (ret); + OPENSSL_free(m); + return ret; } static int dsa_param_decode(EVP_PKEY *pkey, const uint8_t **pder, int derlen) { @@ -550,9 +527,7 @@ static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, rv = 1; err: - if (m) { - OPENSSL_free(m); - } + OPENSSL_free(m); DSA_SIG_free(dsa_sig); return rv; } diff --git a/crypto/evp/p_ec.c b/crypto/evp/p_ec.c index bbf470bb..73c00d8f 100644 --- a/crypto/evp/p_ec.c +++ b/crypto/evp/p_ec.c @@ -119,9 +119,7 @@ static void pkey_ec_cleanup(EVP_PKEY_CTX *ctx) { return; } - if (dctx->gen_group) { - EC_GROUP_free(dctx->gen_group); - } + EC_GROUP_free(dctx->gen_group); OPENSSL_free(dctx); } @@ -212,9 +210,7 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) { OPENSSL_PUT_ERROR(EVP, pkey_ec_ctrl, EVP_R_INVALID_CURVE); return 0; } - if (dctx->gen_group) { - EC_GROUP_free(dctx->gen_group); - } + EC_GROUP_free(dctx->gen_group); dctx->gen_group = group; return 1; diff --git a/crypto/evp/p_ec_asn1.c b/crypto/evp/p_ec_asn1.c index 6c4afb18..1fe41e72 100644 --- a/crypto/evp/p_ec_asn1.c +++ b/crypto/evp/p_ec_asn1.c @@ -481,18 +481,10 @@ err: if (!ret) { OPENSSL_PUT_ERROR(EVP, do_EC_KEY_print, reason); } - if (pub_key_bytes) { - OPENSSL_free(pub_key_bytes); - } - if (order) { - BN_free(order); - } - if (ctx) { - BN_CTX_free(ctx); - } - if (buffer != NULL) { - OPENSSL_free(buffer); - } + OPENSSL_free(pub_key_bytes); + BN_free(order); + BN_CTX_free(ctx); + OPENSSL_free(buffer); return ret; } diff --git a/crypto/evp/p_rsa.c b/crypto/evp/p_rsa.c index be99f92a..5abc075a 100644 --- a/crypto/evp/p_rsa.c +++ b/crypto/evp/p_rsa.c @@ -127,9 +127,7 @@ static int pkey_rsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) { dctx->md = sctx->md; dctx->mgf1md = sctx->mgf1md; if (sctx->oaep_label) { - if (dctx->oaep_label) { - OPENSSL_free(dctx->oaep_label); - } + OPENSSL_free(dctx->oaep_label); dctx->oaep_label = BUF_memdup(sctx->oaep_label, sctx->oaep_labellen); if (!dctx->oaep_label) { return 0; @@ -147,15 +145,9 @@ static void pkey_rsa_cleanup(EVP_PKEY_CTX *ctx) { return; } - if (rctx->pub_exp) { - BN_free(rctx->pub_exp); - } - if (rctx->tbuf) { - OPENSSL_free(rctx->tbuf); - } - if (rctx->oaep_label) { - OPENSSL_free(rctx->oaep_label); - } + BN_free(rctx->pub_exp); + OPENSSL_free(rctx->tbuf); + OPENSSL_free(rctx->oaep_label); OPENSSL_free(rctx); } @@ -463,9 +455,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) { OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PADDING_MODE); return 0; } - if (rctx->oaep_label) { - OPENSSL_free(rctx->oaep_label); - } + OPENSSL_free(rctx->oaep_label); if (p2 && p1 > 0) { /* TODO(fork): this seems wrong. Shouldn't it take a copy of the * buffer? */ diff --git a/crypto/evp/p_rsa_asn1.c b/crypto/evp/p_rsa_asn1.c index 8acf1ce9..1e2d3f6e 100644 --- a/crypto/evp/p_rsa_asn1.c +++ b/crypto/evp/p_rsa_asn1.c @@ -245,9 +245,7 @@ static int do_rsa_print(BIO *out, const RSA *rsa, int off, ret = 1; err: - if (m != NULL) { - OPENSSL_free(m); - } + OPENSSL_free(m); return ret; } @@ -394,12 +392,8 @@ static int rsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, pss = rsa_pss_decode(sigalg, &maskHash); rv = rsa_pss_param_print(bp, pss, maskHash, indent); - if (pss) { - RSA_PSS_PARAMS_free(pss); - } - if (maskHash) { - X509_ALGOR_free(maskHash); - } + RSA_PSS_PARAMS_free(pss); + X509_ALGOR_free(maskHash); if (!rv) { return 0; } @@ -463,12 +457,8 @@ static int rsa_md_to_mgf1(X509_ALGOR **palg, const EVP_MD *mgf1md) { stmp = NULL; err: - if (stmp) { - ASN1_STRING_free(stmp); - } - if (algtmp) { - X509_ALGOR_free(algtmp); - } + ASN1_STRING_free(stmp); + X509_ALGOR_free(algtmp); if (*palg) { return 1; } |