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>
diff --git a/crypto/ecdsa/ecdsa.c b/crypto/ecdsa/ecdsa.c
index b8030cb..b71799e 100644
--- a/crypto/ecdsa/ecdsa.c
+++ b/crypto/ecdsa/ecdsa.c
@@ -97,12 +97,8 @@
ret = ECDSA_do_verify(digest, digest_len, s, eckey);
err:
- if (der != NULL) {
- OPENSSL_free(der);
- }
- if (s != NULL) {
- ECDSA_SIG_free(s);
- }
+ OPENSSL_free(der);
+ ECDSA_SIG_free(s);
return ret;
}
@@ -231,9 +227,7 @@
err:
BN_CTX_end(ctx);
BN_CTX_free(ctx);
- if (point) {
- EC_POINT_free(point);
- }
+ EC_POINT_free(point);
return ret;
}
@@ -333,12 +327,8 @@
goto err;
}
/* clear old values if necessary */
- if (*rp != NULL) {
- BN_clear_free(*rp);
- }
- if (*kinvp != NULL) {
- BN_clear_free(*kinvp);
- }
+ BN_clear_free(*rp);
+ BN_clear_free(*kinvp);
/* save the pre-computed values */
*rp = r;
@@ -347,25 +337,15 @@
err:
if (!ret) {
- if (k != NULL) {
- BN_clear_free(k);
- }
- if (r != NULL) {
- BN_clear_free(r);
- }
+ BN_clear_free(k);
+ BN_clear_free(r);
}
if (ctx_in == NULL) {
BN_CTX_free(ctx);
}
- if (order != NULL) {
- BN_free(order);
- }
- if (tmp_point != NULL) {
- EC_POINT_free(tmp_point);
- }
- if (X) {
- BN_clear_free(X);
- }
+ BN_free(order);
+ EC_POINT_free(tmp_point);
+ BN_clear_free(X);
return ret;
}
@@ -464,21 +444,11 @@
ECDSA_SIG_free(ret);
ret = NULL;
}
- if (ctx) {
- BN_CTX_free(ctx);
- }
- if (m) {
- BN_clear_free(m);
- }
- if (tmp) {
- BN_clear_free(tmp);
- }
- if (order) {
- BN_free(order);
- }
- if (kinv) {
- BN_clear_free(kinv);
- }
+ BN_CTX_free(ctx);
+ BN_clear_free(m);
+ BN_clear_free(tmp);
+ BN_free(order);
+ BN_clear_free(kinv);
return ret;
}
diff --git a/crypto/err/err.c b/crypto/err/err.c
index e7cbbc8..53ec538 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -135,7 +135,7 @@
/* err_clear_data frees the optional |data| member of the given error. */
static void err_clear_data(struct err_error_st *error) {
- if (error->data != NULL && (error->flags & ERR_FLAG_MALLOCED) != 0) {
+ if ((error->flags & ERR_FLAG_MALLOCED) != 0) {
OPENSSL_free(error->data);
}
error->data = NULL;
@@ -167,9 +167,7 @@
for (i = 0; i < ERR_NUM_ERRORS; i++) {
err_clear(&state->errors[i]);
}
- if (state->to_free) {
- OPENSSL_free(state->to_free);
- }
+ OPENSSL_free(state->to_free);
OPENSSL_free(state);
}
@@ -242,9 +240,7 @@
* error queue. */
if (inc) {
if (error->flags & ERR_FLAG_MALLOCED) {
- if (state->to_free) {
- OPENSSL_free(state->to_free);
- }
+ OPENSSL_free(state->to_free);
state->to_free = error->data;
}
error->data = NULL;
@@ -312,10 +308,8 @@
for (i = 0; i < ERR_NUM_ERRORS; i++) {
err_clear(&state->errors[i]);
}
- if (state->to_free) {
- OPENSSL_free(state->to_free);
- state->to_free = NULL;
- }
+ OPENSSL_free(state->to_free);
+ state->to_free = NULL;
state->top = state->bottom = 0;
}
diff --git a/crypto/evp/asn1.c b/crypto/evp/asn1.c
index 27ae017..3df9f52 100644
--- a/crypto/evp/asn1.c
+++ b/crypto/evp/asn1.c
@@ -105,7 +105,7 @@
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 e94ca1c..4d927ff 100644
--- a/crypto/evp/evp_ctx.c
+++ b/crypto/evp/evp_ctx.c
@@ -125,9 +125,7 @@
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 @@
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 @@
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 fce644b..0ac7da7 100644
--- a/crypto/evp/p_dsa_asn1.c
+++ b/crypto/evp/p_dsa_asn1.c
@@ -122,12 +122,8 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
if (a == NULL) {
return 0;
}
- if (*out != NULL) {
- BN_free(*out);
- }
+ BN_free(*out);
*out = a;
return 1;
@@ -463,10 +442,8 @@
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 @@
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 bbf470b..73c00d8 100644
--- a/crypto/evp/p_ec.c
+++ b/crypto/evp/p_ec.c
@@ -119,9 +119,7 @@
return;
}
- if (dctx->gen_group) {
- EC_GROUP_free(dctx->gen_group);
- }
+ EC_GROUP_free(dctx->gen_group);
OPENSSL_free(dctx);
}
@@ -212,9 +210,7 @@
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 6c4afb1..1fe41e7 100644
--- a/crypto/evp/p_ec_asn1.c
+++ b/crypto/evp/p_ec_asn1.c
@@ -481,18 +481,10 @@
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 be99f92..5abc075 100644
--- a/crypto/evp/p_rsa.c
+++ b/crypto/evp/p_rsa.c
@@ -127,9 +127,7 @@
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 @@
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 @@
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 8acf1ce..1e2d3f6 100644
--- a/crypto/evp/p_rsa_asn1.c
+++ b/crypto/evp/p_rsa_asn1.c
@@ -245,9 +245,7 @@
ret = 1;
err:
- if (m != NULL) {
- OPENSSL_free(m);
- }
+ OPENSSL_free(m);
return ret;
}
@@ -394,12 +392,8 @@
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 @@
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;
}
diff --git a/crypto/ex_data.c b/crypto/ex_data.c
index 8f199fd..10fefc8 100644
--- a/crypto/ex_data.c
+++ b/crypto/ex_data.c
@@ -306,10 +306,8 @@
sk_CRYPTO_EX_DATA_FUNCS_free(func_pointers);
- if (ad->sk) {
- sk_void_free(ad->sk);
- ad->sk = NULL;
- }
+ sk_void_free(ad->sk);
+ ad->sk = NULL;
}
void CRYPTO_cleanup_all_ex_data(void) {}