diff --git a/apps/apps.c b/apps/apps.c index 233d382cd5f5b37786d03166b5b02f6591f589c5..1dcaabf87d6dfd1fabe988b203491e24b6a36f7f 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -1114,8 +1114,7 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin, goto end; } end: - if (key != NULL) - BIO_free(key); + BIO_free(key); if (pkey == NULL) BIO_printf(err, "unable to load %s\n", key_descrip); return (pkey); @@ -1682,8 +1681,7 @@ BIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai) ai = NULL; } err: - if (in != NULL) - BIO_free(in); + BIO_free(in); if (ai != NULL) ASN1_INTEGER_free(ai); return (ret); @@ -1741,8 +1739,7 @@ int save_serial(char *serialfile, char *suffix, BIGNUM *serial, ai = NULL; } err: - if (out != NULL) - BIO_free_all(out); + BIO_free_all(out); if (ai != NULL) ASN1_INTEGER_free(ai); return (ret); @@ -1896,8 +1893,7 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr) NCONF_free(dbattr_conf); if (tmpdb) TXT_DB_free(tmpdb); - if (in) - BIO_free_all(in); + BIO_free_all(in); return retdb; } diff --git a/apps/asn1pars.c b/apps/asn1pars.c index da950115e3c21ac916bf1f46da53cffafefb38c4..1576f1cc050b052d8613f2a61a6d90ea4800010d 100644 --- a/apps/asn1pars.c +++ b/apps/asn1pars.c @@ -370,12 +370,9 @@ int MAIN(int argc, char **argv) ret = 0; end: BIO_free(derout); - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); - if (b64 != NULL) - BIO_free(b64); + BIO_free(in); + BIO_free_all(out); + BIO_free(b64); if (ret != 0) ERR_print_errors(bio_err); if (buf != NULL) diff --git a/apps/ca.c b/apps/ca.c index b498b0a25a3fa5804a4727f09324f91ecf341e54..89bece8ed1a6c386c0f1663029204af900b526ae 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -1566,8 +1566,7 @@ static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, err: if (req != NULL) X509_REQ_free(req); - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ok); } diff --git a/apps/ciphers.c b/apps/ciphers.c index 803b021f5c46fcb33e3cea5844150e5c09a0a2e2..6c7ff01eeaebf5a64231abd545be565ed4d333ce 100644 --- a/apps/ciphers.c +++ b/apps/ciphers.c @@ -227,8 +227,7 @@ int MAIN(int argc, char **argv) SSL_CTX_free(ctx); if (ssl != NULL) SSL_free(ssl); - if (STDout != NULL) - BIO_free_all(STDout); + BIO_free_all(STDout); apps_shutdown(); OPENSSL_EXIT(ret); } diff --git a/apps/crl2p7.c b/apps/crl2p7.c index 0763817e617bc81349f813f1fd472c44a86409dc..ab0c3d6d287f548aa6741ea420e7bb70b07638ba 100644 --- a/apps/crl2p7.c +++ b/apps/crl2p7.c @@ -268,10 +268,8 @@ int MAIN(int argc, char **argv) } ret = 0; end: - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); if (p7 != NULL) PKCS7_free(p7); if (crl != NULL) @@ -326,8 +324,7 @@ static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile) ret = count; end: /* never need to OPENSSL_free x */ - if (in != NULL) - BIO_free(in); + BIO_free(in); if (sk != NULL) sk_X509_INFO_free(sk); return (ret); diff --git a/apps/dgst.c b/apps/dgst.c index 95e5fa3fc7b7d5cb9f4230f5c9dd3cb71492dba3..ac3b583793b9a8ad3dcdfa6e242c9d23b0e7ad04 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -518,8 +518,7 @@ int MAIN(int argc, char **argv) OPENSSL_cleanse(buf, BUFSIZE); OPENSSL_free(buf); } - if (in != NULL) - BIO_free(in); + BIO_free(in); if (passin) OPENSSL_free(passin); BIO_free_all(out); @@ -530,8 +529,7 @@ int MAIN(int argc, char **argv) sk_OPENSSL_STRING_free(macopts); if (sigbuf) OPENSSL_free(sigbuf); - if (bmd != NULL) - BIO_free(bmd); + BIO_free(bmd); apps_shutdown(); OPENSSL_EXIT(err); } diff --git a/apps/dh.c b/apps/dh.c index a9216336e59561f17cf3a821ecbca58bdfa6886b..1b653f548a6de4780cd8aa0d7bee4bdc798d6822 100644 --- a/apps/dh.c +++ b/apps/dh.c @@ -310,10 +310,8 @@ int MAIN(int argc, char **argv) } ret = 0; end: - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); DH_free(dh); apps_shutdown(); OPENSSL_EXIT(ret); diff --git a/apps/dhparam.c b/apps/dhparam.c index 12a2be64550be3d609eea7ebeca0610c1799ed25..fc5962a7a1d46867f2257ab75483907af30559bb 100644 --- a/apps/dhparam.c +++ b/apps/dhparam.c @@ -515,10 +515,8 @@ int MAIN(int argc, char **argv) } ret = 0; end: - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); DH_free(dh); apps_shutdown(); OPENSSL_EXIT(ret); diff --git a/apps/dsa.c b/apps/dsa.c index 8d085bcef2f691290cbc748fbd7a02f7d8f5eaa2..1ea0d7346d6fdaf9c67f6eb0e5a74574340f8b87 100644 --- a/apps/dsa.c +++ b/apps/dsa.c @@ -356,10 +356,8 @@ int MAIN(int argc, char **argv) } else ret = 0; end: - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); DSA_free(dsa); if (passin) OPENSSL_free(passin); diff --git a/apps/dsaparam.c b/apps/dsaparam.c index fc1c81760410fcd40acec3bd2c233441262c5314..f63ecb28ecb6c35e0ae208646313ace4c2d05d07 100644 --- a/apps/dsaparam.c +++ b/apps/dsaparam.c @@ -434,10 +434,8 @@ int MAIN(int argc, char **argv) end: if (cb != NULL) BN_GENCB_free(cb); - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); DSA_free(dsa); apps_shutdown(); OPENSSL_EXIT(ret); diff --git a/apps/ec.c b/apps/ec.c index b04dadaf18c0a0b6f13fbc42c6f416adf787f73c..2064723eb1dc945259abdffb9e01e285e35eb1a9 100644 --- a/apps/ec.c +++ b/apps/ec.c @@ -343,10 +343,8 @@ int MAIN(int argc, char **argv) } else ret = 0; end: - if (in) - BIO_free(in); - if (out) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); if (eckey) EC_KEY_free(eckey); if (passin) diff --git a/apps/ecparam.c b/apps/ecparam.c index 06ac77b838a380ec8861ccd1037bca487731406d..d4177474d50a3e74d88a42ff2654f3730290a407 100644 --- a/apps/ecparam.c +++ b/apps/ecparam.c @@ -621,10 +621,8 @@ int MAIN(int argc, char **argv) BN_free(ec_cofactor); if (buffer) OPENSSL_free(buffer); - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); if (group != NULL) EC_GROUP_free(group); apps_shutdown(); diff --git a/apps/enc.c b/apps/enc.c index 1739b7ec23aecf71ac35dbb7be17861cf69be58d..b95a6a2031625c77ac65777d361fdffffb30774b 100644 --- a/apps/enc.c +++ b/apps/enc.c @@ -657,17 +657,12 @@ int MAIN(int argc, char **argv) OPENSSL_free(strbuf); if (buff != NULL) OPENSSL_free(buff); - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); - if (benc != NULL) - BIO_free(benc); - if (b64 != NULL) - BIO_free(b64); + BIO_free(in); + BIO_free_all(out); + BIO_free(benc); + BIO_free(b64); #ifdef ZLIB - if (bzl != NULL) - BIO_free(bzl); + BIO_free(bzl); #endif if (pass) OPENSSL_free(pass); diff --git a/apps/engine.c b/apps/engine.c index 8a1e746ab604a6316cf8fce1763d2819c0231f97..53864650ac8ad79b1203a505dfb11a2f219fd660 100644 --- a/apps/engine.c +++ b/apps/engine.c @@ -497,8 +497,7 @@ int MAIN(int argc, char **argv) sk_OPENSSL_STRING_pop_free(engines, identity); sk_OPENSSL_STRING_pop_free(pre_cmds, identity); sk_OPENSSL_STRING_pop_free(post_cmds, identity); - if (bio_out != NULL) - BIO_free_all(bio_out); + BIO_free_all(bio_out); apps_shutdown(); OPENSSL_EXIT(ret); } diff --git a/apps/errstr.c b/apps/errstr.c index c2d4fdec35ad023d4363bddace132dcb83c3c959..668c5f3024390d0a11964e34984c5d80ecdaa279 100644 --- a/apps/errstr.c +++ b/apps/errstr.c @@ -100,8 +100,7 @@ int MAIN(int argc, char **argv) lh_ERR_STRING_DATA_node_usage_stats_bio(ERR_get_string_table(), out); } - if (out != NULL) - BIO_free_all(out); + BIO_free_all(out); argc--; argv++; } diff --git a/apps/gendh.c b/apps/gendh.c index 6102b79511ad51b802dfcf540cd8db7ad603c262..904bcf3a945a956b3a4a9fd36e53942efbeff226 100644 --- a/apps/gendh.c +++ b/apps/gendh.c @@ -210,8 +210,7 @@ int MAIN(int argc, char **argv) end: if (ret != 0) ERR_print_errors(bio_err); - if (out != NULL) - BIO_free_all(out); + BIO_free_all(out); DH_free(dh); if (cb != NULL) BN_GENCB_free(cb); diff --git a/apps/gendsa.c b/apps/gendsa.c index d330a0100280fcdf2908dd863aca2a2d6f36195c..8288eb90ab01a74ce042ee07b5baecc651acfaac 100644 --- a/apps/gendsa.c +++ b/apps/gendsa.c @@ -267,10 +267,8 @@ int MAIN(int argc, char **argv) end: if (ret != 0) ERR_print_errors(bio_err); - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); DSA_free(dsa); if (passout) OPENSSL_free(passout); diff --git a/apps/genpkey.c b/apps/genpkey.c index fc19a928c3f0e78366506e266ce9437e046e9efc..5b7f4335b19ce65900290de96308907d22d22bcb 100644 --- a/apps/genpkey.c +++ b/apps/genpkey.c @@ -272,8 +272,7 @@ int MAIN(int argc, char **argv) EVP_PKEY_free(pkey); if (ctx) EVP_PKEY_CTX_free(ctx); - if (out) - BIO_free_all(out); + BIO_free_all(out); BIO_free(in); if (pass) OPENSSL_free(pass); diff --git a/apps/genrsa.c b/apps/genrsa.c index 1b06c82e40a0008a630887d02238e0ba0e18170d..cf60219642e622fc36ab4854cc14e11aa3384d35 100644 --- a/apps/genrsa.c +++ b/apps/genrsa.c @@ -312,8 +312,7 @@ int MAIN(int argc, char **argv) if (cb) BN_GENCB_free(cb); RSA_free(rsa); - if (out) - BIO_free_all(out); + BIO_free_all(out); if (passout) OPENSSL_free(passout); if (ret != 0) diff --git a/apps/ocsp.c b/apps/ocsp.c index 83a71752b10c760a7cb6c2162a3c00b828678bbc..95380964a358dbe4bf2d4f48839df37e012d2801 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -1362,8 +1362,7 @@ OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req, if (!resp) BIO_printf(bio_err, "Error querying OCSP responder\n"); end: - if (cbio) - BIO_free_all(cbio); + BIO_free_all(cbio); if (ctx) SSL_CTX_free(ctx); return resp; diff --git a/apps/openssl.c b/apps/openssl.c index e070a444a5b9472004ba610bf65e26bc0dbef13d..e93aed702a02f3976f8147f65c2c11836b852716 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -431,10 +431,8 @@ int main(int Argc, char *ARGV[]) #endif apps_shutdown(); CRYPTO_mem_leaks(bio_err); - if (bio_err != NULL) { - BIO_free(bio_err); - bio_err = NULL; - } + BIO_free(bio_err); + bio_err = NULL; OPENSSL_EXIT(ret); } diff --git a/apps/passwd.c b/apps/passwd.c index 798a6d593616fab4ccb1725658e2b9d0bd1e3b80..2814b32c75e5a0a07c532163357cf757cb25dcdd 100644 --- a/apps/passwd.c +++ b/apps/passwd.c @@ -273,10 +273,8 @@ int MAIN(int argc, char **argv) OPENSSL_free(salt_malloc); if (passwd_malloc) OPENSSL_free(passwd_malloc); - if (in) - BIO_free(in); - if (out) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); apps_shutdown(); OPENSSL_EXIT(ret); } diff --git a/apps/pkcs7.c b/apps/pkcs7.c index 643507f216a046d214e372e54653af6862aa7111..1b07c022a4fee310d394a1e9d21d3dd353f1486d 100644 --- a/apps/pkcs7.c +++ b/apps/pkcs7.c @@ -299,10 +299,8 @@ int MAIN(int argc, char **argv) end: if (p7 != NULL) PKCS7_free(p7); - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free(in); + BIO_free_all(out); apps_shutdown(); OPENSSL_EXIT(ret); } diff --git a/apps/rand.c b/apps/rand.c index e159da37be18e77a34b43b32982f1045d9c0b73e..45f16b9094bbcc529901a2c49db4aaf0c5a1cfec 100644 --- a/apps/rand.c +++ b/apps/rand.c @@ -222,8 +222,7 @@ int MAIN(int argc, char **argv) err: ERR_print_errors(bio_err); - if (out) - BIO_free_all(out); + BIO_free_all(out); apps_shutdown(); OPENSSL_EXIT(ret); } diff --git a/apps/rsa.c b/apps/rsa.c index ac4a3c43efe9ce0760c14bb03a943c9d7349cf1c..2f3f871a33378a4c71f03e2c6a053b6bf48bd486 100644 --- a/apps/rsa.c +++ b/apps/rsa.c @@ -422,8 +422,7 @@ int MAIN(int argc, char **argv) } else ret = 0; end: - if (out != NULL) - BIO_free_all(out); + BIO_free_all(out); RSA_free(rsa); if (passin) OPENSSL_free(passin); diff --git a/apps/s_client.c b/apps/s_client.c index cdea32280c45b29280af6c3818b550c6b34c7ce2..08749830ba9249d4b028907b94106acdada7118f 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -2059,14 +2059,10 @@ int MAIN(int argc, char **argv) OPENSSL_cleanse(mbuf, BUFSIZZ); OPENSSL_free(mbuf); } - if (bio_c_out != NULL) { - BIO_free(bio_c_out); - bio_c_out = NULL; - } - if (bio_c_msg != NULL) { - BIO_free(bio_c_msg); - bio_c_msg = NULL; - } + BIO_free(bio_c_out); + bio_c_out = NULL; + BIO_free(bio_c_msg); + bio_c_msg = NULL; apps_shutdown(); OPENSSL_EXIT(ret); } diff --git a/apps/s_server.c b/apps/s_server.c index c3884d26ab4b4764f2995fe73a6ead119bce4d54..37c40cb2fb6ed24903a718ca1b01d9ee8fc68429 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -2039,8 +2039,7 @@ int MAIN(int argc, char *argv[]) X509_free(s_cert2); if (s_key2) EVP_PKEY_free(s_key2); - if (serverinfo_in != NULL) - BIO_free(serverinfo_in); + BIO_free(serverinfo_in); # ifndef OPENSSL_NO_NEXTPROTONEG if (next_proto.data) OPENSSL_free(next_proto.data); @@ -2057,14 +2056,10 @@ int MAIN(int argc, char *argv[]) if (jpake_secret && psk_key) OPENSSL_free(psk_key); #endif - if (bio_s_out != NULL) { - BIO_free(bio_s_out); - bio_s_out = NULL; - } - if (bio_s_msg != NULL) { - BIO_free(bio_s_msg); - bio_s_msg = NULL; - } + BIO_free(bio_s_out); + bio_s_out = NULL; + BIO_free(bio_s_msg); + bio_s_msg = NULL; apps_shutdown(); OPENSSL_EXIT(ret); } @@ -2661,8 +2656,7 @@ static DH *load_dh_param(const char *dhfile) goto err; ret = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); err: - if (bio != NULL) - BIO_free(bio); + BIO_free(bio); return (ret); } #endif @@ -3021,9 +3015,7 @@ static int www_body(char *hostname, int s, int stype, unsigned char *context) if (buf != NULL) OPENSSL_free(buf); - if (io != NULL) - BIO_free_all(io); -/* if (ssl_bio != NULL) BIO_free(ssl_bio);*/ + BIO_free_all(io); return (ret); } @@ -3159,8 +3151,7 @@ static int rev_body(char *hostname, int s, int stype, unsigned char *context) if (buf != NULL) OPENSSL_free(buf); - if (io != NULL) - BIO_free_all(io); + BIO_free_all(io); return (ret); } diff --git a/apps/sess_id.c b/apps/sess_id.c index 9400af964efd0efd0372f5be7ba13fd9e59dee8d..53ccbb35762333ac3ce5bae12ed2a11e7fa2b8b8 100644 --- a/apps/sess_id.c +++ b/apps/sess_id.c @@ -237,8 +237,7 @@ int MAIN(int argc, char **argv) } ret = 0; end: - if (out != NULL) - BIO_free_all(out); + BIO_free_all(out); if (x != NULL) SSL_SESSION_free(x); apps_shutdown(); @@ -279,7 +278,6 @@ static SSL_SESSION *load_sess_id(char *infile, int format) } end: - if (in != NULL) - BIO_free(in); + BIO_free(in); return (x); } diff --git a/apps/ts.c b/apps/ts.c index fb77d6a594f203eac3b8c36cb12f6e360b41c760..4c32ada41004547585d715c9877ec6e0f4e93c2e 100644 --- a/apps/ts.c +++ b/apps/ts.c @@ -162,8 +162,8 @@ int MAIN(int argc, char **argv) apps_startup(); if (bio_err == NULL && (bio_err = BIO_new(BIO_s_file())) != NULL) { - free_bio_err = 1; BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT); + free_bio_err = 1; } if (!load_config(bio_err, NULL)) diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index e96fb0209434fc4e3b67c4b49a7cb783080fb770..e810345579e23ada85308e34b8e223c181694bb6 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -650,8 +650,7 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) BIO_write(bpart, linebuf, len); } } - if (bpart != NULL) - BIO_free(bpart); + BIO_free(bpart); return 0; } diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c index 0b4fd1dd9e73ef2521d94cd5e9079e9e3c97a2cb..d4be23c1901c96d84bb60b5350149e84e7fc4d5f 100644 --- a/crypto/asn1/bio_asn1.c +++ b/crypto/asn1/bio_asn1.c @@ -179,8 +179,8 @@ static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) static int asn1_bio_free(BIO *b) { - BIO_ASN1_BUF_CTX *ctx; - ctx = (BIO_ASN1_BUF_CTX *)b->ptr; + BIO_ASN1_BUF_CTX *ctx = (BIO_ASN1_BUF_CTX *)b->ptr; + if (ctx == NULL) return 0; if (ctx->buf) diff --git a/crypto/asn1/bio_ndef.c b/crypto/asn1/bio_ndef.c index 4a73ca9eac514ad2454be3281681f26f46e97a67..1018787a63c2166021cd8515fc6c46005136b875 100644 --- a/crypto/asn1/bio_ndef.c +++ b/crypto/asn1/bio_ndef.c @@ -142,8 +142,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) return sarg.ndef_bio; err: - if (asn_bio) - BIO_free(asn_bio); + BIO_free(asn_bio); if (ndef_aux) OPENSSL_free(ndef_aux); return NULL; diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 11e0142de808c74abf67a27493b8300feda065c2..a5d8680d4802c4ab7162be41fa78ef9f5534bf8d 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -549,8 +549,7 @@ BIO *BIO_dup_chain(BIO *in) } return (ret); err: - if (ret != NULL) - BIO_free(ret); + BIO_free(ret); return (NULL); } diff --git a/crypto/bio/bss_acpt.c b/crypto/bio/bss_acpt.c index 5aa06cf167cc794fa1bb642d8705591848e2f6bb..72f7bd21dee174131ccc0b3706333c31550cf0e5 100644 --- a/crypto/bio/bss_acpt.c +++ b/crypto/bio/bss_acpt.c @@ -155,8 +155,7 @@ static void BIO_ACCEPT_free(BIO_ACCEPT *a) OPENSSL_free(a->param_addr); if (a->addr != NULL) OPENSSL_free(a->addr); - if (a->bio_chain != NULL) - BIO_free(a->bio_chain); + BIO_free(a->bio_chain); OPENSSL_free(a); } @@ -360,8 +359,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr) } else if (num == 1) { data->accept_nbio = (ptr != NULL); } else if (num == 2) { - if (data->bio_chain != NULL) - BIO_free(data->bio_chain); + BIO_free(data->bio_chain); data->bio_chain = (BIO *)ptr; } } @@ -448,10 +446,8 @@ BIO *BIO_new_accept(const char *str) return (NULL); if (BIO_set_accept_port(ret, str)) return (ret); - else { - BIO_free(ret); - return (NULL); - } + BIO_free(ret); + return (NULL); } #endif diff --git a/crypto/bio/bss_bio.c b/crypto/bio/bss_bio.c index d629a37a5a1dbfa85efbc1506f4969e828af52a9..c6bb3d68857a722c0506dfa105735ce1dec03e98 100644 --- a/crypto/bio/bss_bio.c +++ b/crypto/bio/bss_bio.c @@ -788,14 +788,10 @@ int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, err: if (ret == 0) { - if (bio1) { - BIO_free(bio1); - bio1 = NULL; - } - if (bio2) { - BIO_free(bio2); - bio2 = NULL; - } + BIO_free(bio1); + bio1 = NULL; + BIO_free(bio2); + bio2 = NULL; } *bio1_p = bio1; diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c index c7f57f1c7ce623d63ff5b4f99e8b759955a684de..e95b4b38d6ee6e9d8a9b3f119bb51c09778d2d1a 100644 --- a/crypto/bio/bss_conn.c +++ b/crypto/bio/bss_conn.c @@ -588,10 +588,8 @@ BIO *BIO_new_connect(const char *str) return (NULL); if (BIO_set_conn_hostname(ret, str)) return (ret); - else { - BIO_free(ret); - return (NULL); - } + BIO_free(ret); + return (NULL); } #endif diff --git a/crypto/cms/cms_lib.c b/crypto/cms/cms_lib.c index 7e1c1e8d94d4b784e87168764918d7f073a22e7a..6d2a0e827514516d531b5a158245718689659881 100644 --- a/crypto/cms/cms_lib.c +++ b/crypto/cms/cms_lib.c @@ -354,8 +354,7 @@ BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm) } return mdbio; err: - if (mdbio) - BIO_free(mdbio); + BIO_free(mdbio); return NULL; } diff --git a/crypto/cms/cms_sd.c b/crypto/cms/cms_sd.c index b8ed1a1bea6333f5367930b74d7428ef683af1ac..c45d30eac1172e36620d5cddf65c67e6fdab11a2 100644 --- a/crypto/cms/cms_sd.c +++ b/crypto/cms/cms_sd.c @@ -806,8 +806,7 @@ BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms) } return chain; err: - if (chain) - BIO_free_all(chain); + BIO_free_all(chain); return NULL; } diff --git a/crypto/cms/cms_smime.c b/crypto/cms/cms_smime.c index 6f6f20d63ac55a8ae4f607b8bfc9a15592783b36..f491ec9e7726059ee843514d26abceb2b06b0232 100644 --- a/crypto/cms/cms_smime.c +++ b/crypto/cms/cms_smime.c @@ -114,7 +114,7 @@ static int cms_copy_content(BIO *out, BIO *in, unsigned int flags) r = 1; err: - if (tmpout && (tmpout != out)) + if (tmpout != out) BIO_free(tmpout); return r; @@ -446,14 +446,13 @@ int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, if (tmpin != dcont) BIO_free(tmpin); } else { - if (dcont && (tmpin == dcont)) do_free_upto(cmsbio, dcont); else BIO_free_all(cmsbio); } - if (tmpout && out != tmpout) + if (out != tmpout) BIO_free_all(tmpout); if (cms_certs) @@ -580,8 +579,7 @@ CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, r = 1; err: - if (rct_cont) - BIO_free(rct_cont); + BIO_free(rct_cont); if (r) return cms; CMS_ContentInfo_free(cms); diff --git a/crypto/dsa/dsatest.c b/crypto/dsa/dsatest.c index bf47816037f2bda22e35324be3fb9b07556f0cfc..a5d40f1eb605a970c6cb7072fca0b371c29744dd 100644 --- a/crypto/dsa/dsatest.c +++ b/crypto/dsa/dsatest.c @@ -218,10 +218,8 @@ int main(int argc, char **argv) ERR_remove_thread_state(NULL); ERR_free_strings(); CRYPTO_mem_leaks(bio_err); - if (bio_err != NULL) { - BIO_free(bio_err); - bio_err = NULL; - } + BIO_free(bio_err); + bio_err = NULL; # ifdef OPENSSL_SYS_NETWARE if (!ret) printf("ERROR\n"); diff --git a/crypto/ecdsa/ecdsatest.c b/crypto/ecdsa/ecdsatest.c index c2132da88250d62cd27ed4fae92ae126d08d48d2..346ccd053fce12400a938a4d9f01311fabf8a2c2 100644 --- a/crypto/ecdsa/ecdsatest.c +++ b/crypto/ecdsa/ecdsatest.c @@ -563,8 +563,7 @@ int main(void) ERR_remove_thread_state(NULL); ERR_free_strings(); CRYPTO_mem_leaks(out); - if (out != NULL) - BIO_free(out); + BIO_free(out); return ret; } #endif diff --git a/crypto/ocsp/ocsp_ht.c b/crypto/ocsp/ocsp_ht.c index aca0d48879f71324890fba86065ec64434d6b7bd..4a06a8e1ef5fd7a45a91289e58a1323fbdda3fe0 100644 --- a/crypto/ocsp/ocsp_ht.c +++ b/crypto/ocsp/ocsp_ht.c @@ -136,8 +136,7 @@ OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline) void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx) { - if (rctx->mem) - BIO_free(rctx->mem); + BIO_free(rctx->mem); if (rctx->iobuf) OPENSSL_free(rctx->iobuf); OPENSSL_free(rctx); diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c index f77326b883d5d4423c857cd203542f24d8a3b79f..b7c66a31609f63b5b5ad316f21c3df44b8f340db 100644 --- a/crypto/pkcs7/pk7_doit.c +++ b/crypto/pkcs7/pk7_doit.c @@ -128,8 +128,7 @@ static int PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg) return 1; err: - if (btmp) - BIO_free(btmp); + BIO_free(btmp); return 0; } @@ -390,16 +389,12 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio) BIO_push(out, bio); else out = bio; - bio = NULL; - if (0) { + return out; + err: - if (out != NULL) - BIO_free_all(out); - if (btmp != NULL) - BIO_free_all(btmp); - out = NULL; - } - return (out); + BIO_free_all(out); + BIO_free_all(btmp); + return NULL; } static int pkcs7_cmp_ri(PKCS7_RECIP_INFO *ri, X509 *pcert) @@ -637,14 +632,10 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) OPENSSL_cleanse(tkey, tkeylen); OPENSSL_free(tkey); } - if (out != NULL) - BIO_free_all(out); - if (btmp != NULL) - BIO_free_all(btmp); - if (etmp != NULL) - BIO_free_all(etmp); - if (bio != NULL) - BIO_free_all(bio); + BIO_free_all(out); + BIO_free_all(btmp); + BIO_free_all(etmp); + BIO_free_all(bio); out = NULL; } return (out); diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c index 9d83a8f6067c1798fb1511056251a2db3d04b7b1..82b9a77b14f167634910b997060fb09c4b3b07d6 100644 --- a/crypto/srp/srp_vfy.c +++ b/crypto/srp/srp_vfy.c @@ -460,8 +460,7 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) if (tmpdb) TXT_DB_free(tmpdb); - if (in) - BIO_free_all(in); + BIO_free_all(in); sk_SRP_gN_free(SRP_gN_tab); diff --git a/crypto/threads/mttest.c b/crypto/threads/mttest.c index ea3784c72f1a14bc9515cb7a7fd8ad5f67f25de2..f6f8df289cd338b1b93508bef20d62d5088747d7 100644 --- a/crypto/threads/mttest.c +++ b/crypto/threads/mttest.c @@ -612,15 +612,11 @@ int doit(char *ctx[4]) } /* The SSL's are optionally freed in the following calls */ - if (c_to_s != NULL) - BIO_free(c_to_s); - if (s_to_c != NULL) - BIO_free(s_to_c); - - if (c_bio != NULL) - BIO_free(c_bio); - if (s_bio != NULL) - BIO_free(s_bio); + BIO_free(c_to_s); + BIO_free(s_to_c); + + BIO_free(c_bio); + BIO_free(s_bio); return (0); } diff --git a/crypto/x509/by_file.c b/crypto/x509/by_file.c index 43a073003d8bf643c9c68116e7b9590d6aa31940..bc1c90cc64e49995bb9c55fd247da2b9190fc1fd 100644 --- a/crypto/x509/by_file.c +++ b/crypto/x509/by_file.c @@ -176,8 +176,7 @@ int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) err: if (x != NULL) X509_free(x); - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } @@ -235,8 +234,7 @@ int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) err: if (x != NULL) X509_CRL_free(x); - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } diff --git a/demos/b64.c b/demos/b64.c index d8ed2a6a04d9bc5995e84897994c69baf4e5c667..fcc69562c134afa33fa109d95d45ffa8c101b4c6 100644 --- a/demos/b64.c +++ b/demos/b64.c @@ -243,13 +243,9 @@ char **argv; OPENSSL_free(strbuf); if (buff != NULL) OPENSSL_free(buff); - if (in != NULL) - BIO_free(in); - if (out != NULL) - BIO_free(out); - if (benc != NULL) - BIO_free(benc); - if (b64 != NULL) - BIO_free(b64); + BIO_free(in); + BIO_free(out); + BIO_free(benc); + BIO_free(b64); EXIT(ret); } diff --git a/demos/bio/saccept.c b/demos/bio/saccept.c index 8c75029384ffd3d0e96d2132b8360c8b1bd8baef..505d98b68f8dd3d081c00d168969c731b7890364 100644 --- a/demos/bio/saccept.c +++ b/demos/bio/saccept.c @@ -22,8 +22,7 @@ BIO *in = NULL; void close_up() { - if (in != NULL) - BIO_free(in); + BIO_free(in); } int main(int argc, char *argv[]) @@ -101,8 +100,7 @@ int main(int argc, char *argv[]) if (ret) { ERR_print_errors_fp(stderr); } - if (in != NULL) - BIO_free(in); + BIO_free(in); exit(ret); return (!ret); } diff --git a/demos/bio/server-arg.c b/demos/bio/server-arg.c index 7ba54dbe50a00d92013bbf987813a601f16b2de0..4f65227e4064c05981df07bb9c584e521b4d9ed0 100644 --- a/demos/bio/server-arg.c +++ b/demos/bio/server-arg.c @@ -137,8 +137,7 @@ int main(int argc, char *argv[]) if (ret) { ERR_print_errors_fp(stderr); } - if (in != NULL) - BIO_free(in); + BIO_free(in); exit(ret); return (!ret); } diff --git a/demos/bio/server-conf.c b/demos/bio/server-conf.c index a09bc9320d1be0567875951979f3a8bd9e09d231..5355839f4fdc189a8ad9ecdab10d9e514206a3a6 100644 --- a/demos/bio/server-conf.c +++ b/demos/bio/server-conf.c @@ -131,8 +131,7 @@ int main(int argc, char *argv[]) if (ret) { ERR_print_errors_fp(stderr); } - if (in != NULL) - BIO_free(in); + BIO_free(in); exit(ret); return (!ret); } diff --git a/demos/cms/cms_comp.c b/demos/cms/cms_comp.c index 059152fe0ed7adadd1da784c75832a782553d901..e117d37b5e8a9b1614810997a93506ace82944b2 100644 --- a/demos/cms/cms_comp.c +++ b/demos/cms/cms_comp.c @@ -50,10 +50,8 @@ int main(int argc, char **argv) if (cms) CMS_ContentInfo_free(cms); - if (in) - BIO_free(in); - if (out) - BIO_free(out); + BIO_free(in); + BIO_free(out); return ret; diff --git a/demos/cms/cms_ddec.c b/demos/cms/cms_ddec.c index 37ac97fd01eb60977ec6596f221fb24facf41299..7247e571122fa3c2c0a44b40cdde01737d6ae735 100644 --- a/demos/cms/cms_ddec.c +++ b/demos/cms/cms_ddec.c @@ -75,14 +75,10 @@ int main(int argc, char **argv) if (rkey) EVP_PKEY_free(rkey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); - if (dcont) - BIO_free(dcont); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); + BIO_free(dcont); return ret; diff --git a/demos/cms/cms_dec.c b/demos/cms/cms_dec.c index 3291eacab4f9daf586b30cec729cc4240ecbd0cc..e9782d7c2338b6204302105360f6205c29d585de 100644 --- a/demos/cms/cms_dec.c +++ b/demos/cms/cms_dec.c @@ -66,12 +66,9 @@ int main(int argc, char **argv) if (rkey) EVP_PKEY_free(rkey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/cms/cms_denc.c b/demos/cms/cms_denc.c index c86a5fd728aed4ffaab193cd01cc0b5639a49dea..852671771c7aecff7bec1c9d19e2ab0e1e8c7f8f 100644 --- a/demos/cms/cms_denc.c +++ b/demos/cms/cms_denc.c @@ -84,14 +84,10 @@ int main(int argc, char **argv) if (recips) sk_X509_pop_free(recips, X509_free); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (dout) - BIO_free(dout); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(dout); + BIO_free(tbio); return ret; diff --git a/demos/cms/cms_enc.c b/demos/cms/cms_enc.c index e8ecb48e277626117832e75ea96101b142e6aa74..4395e6b04f11087ccf47e88937f6cac6040b3da2 100644 --- a/demos/cms/cms_enc.c +++ b/demos/cms/cms_enc.c @@ -80,12 +80,9 @@ int main(int argc, char **argv) if (recips) sk_X509_pop_free(recips, X509_free); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/cms/cms_sign.c b/demos/cms/cms_sign.c index 4bf85d13844e2dc7cf5ea006a87bc9ba139de5d2..9f2cff0dbe6fae00aaef88905c0de55730a65584 100644 --- a/demos/cms/cms_sign.c +++ b/demos/cms/cms_sign.c @@ -76,12 +76,9 @@ int main(int argc, char **argv) if (skey) EVP_PKEY_free(skey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/cms/cms_sign2.c b/demos/cms/cms_sign2.c index 7e98a517138379e8b503494e75993fe21284aba7..23c6eb8f9f6524d3a85c81b39c43db69d9b7d4ad 100644 --- a/demos/cms/cms_sign2.c +++ b/demos/cms/cms_sign2.c @@ -90,12 +90,9 @@ int main(int argc, char **argv) if (skey) EVP_PKEY_free(skey2); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/cms/cms_uncomp.c b/demos/cms/cms_uncomp.c index 392f4b4502d62cb886acf601fd8db3ca7c3220ce..8d45834c34a889fc56a81dade506111b1d143916 100644 --- a/demos/cms/cms_uncomp.c +++ b/demos/cms/cms_uncomp.c @@ -45,10 +45,8 @@ int main(int argc, char **argv) if (cms) CMS_ContentInfo_free(cms); - if (in) - BIO_free(in); - if (out) - BIO_free(out); + BIO_free(in); + BIO_free(out); return ret; diff --git a/demos/cms/cms_ver.c b/demos/cms/cms_ver.c index ca935517a7a981645be92316a23588381ecf3577..422753163e62215365110f4b0a3ba53aa292c12f 100644 --- a/demos/cms/cms_ver.c +++ b/demos/cms/cms_ver.c @@ -73,12 +73,9 @@ int main(int argc, char **argv) if (cacert) X509_free(cacert); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/smime/smdec.c b/demos/smime/smdec.c index 6814d5199b791d417dde96eb01b801c06df3a82e..b50f8dffaf0d4493af9e059e895b2c0a04d2c488 100644 --- a/demos/smime/smdec.c +++ b/demos/smime/smdec.c @@ -66,12 +66,9 @@ int main(int argc, char **argv) if (rkey) EVP_PKEY_free(rkey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/smime/smenc.c b/demos/smime/smenc.c index 18bf7b1618b79d9a1f9a6595cbf75ec4c38e6778..5a85537ad0ef45e1db7203a3be241bcb82cc464d 100644 --- a/demos/smime/smenc.c +++ b/demos/smime/smenc.c @@ -80,12 +80,9 @@ int main(int argc, char **argv) if (recips) sk_X509_pop_free(recips, X509_free); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/smime/smsign.c b/demos/smime/smsign.c index c7bf86d37062eaa4e13ef3429d6fbcc42f1e9f70..6b9dfdd771245d904c1b0ccc4c422c2ce4677e18 100644 --- a/demos/smime/smsign.c +++ b/demos/smime/smsign.c @@ -76,12 +76,9 @@ int main(int argc, char **argv) if (skey) EVP_PKEY_free(skey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/smime/smsign2.c b/demos/smime/smsign2.c index a116094341ba9808e4cdd634835a69a12b3f3ce5..5d9de35c46c784bd73f1419342f7ec3dc7ee5adc 100644 --- a/demos/smime/smsign2.c +++ b/demos/smime/smsign2.c @@ -90,12 +90,9 @@ int main(int argc, char **argv) if (skey) EVP_PKEY_free(skey2); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/demos/smime/smver.c b/demos/smime/smver.c index 21937df3077830ad62d7e7fb589c2eee8e1dbc3a..4088d3c38e3fa9b39443cbb67dd304d57cba6f3c 100644 --- a/demos/smime/smver.c +++ b/demos/smime/smver.c @@ -73,12 +73,9 @@ int main(int argc, char **argv) if (cacert) X509_free(cacert); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + BIO_free(in); + BIO_free(out); + BIO_free(tbio); return ret; diff --git a/doc/crypto/BIO_new.pod b/doc/crypto/BIO_new.pod index 2a245fc8de83e962aec0153cf22a872199144c66..76679f3da4fd30d6c37adfd8ea45f859e0883ed5 100644 --- a/doc/crypto/BIO_new.pod +++ b/doc/crypto/BIO_new.pod @@ -21,13 +21,16 @@ The BIO_new() function returns a new BIO using method B. BIO_set() sets the method of an already existing BIO. BIO_free() frees up a single BIO, BIO_vfree() also frees up a single BIO -but it does not return a value. Calling BIO_free() may also have some effect +but it does not return a value. +If B is NULL nothing is done. +Calling BIO_free() may also have some effect on the underlying I/O structure, for example it may close the file being referred to under certain circumstances. For more details see the individual BIO_METHOD descriptions. BIO_free_all() frees up an entire BIO chain, it does not halt if an error occurs freeing up an individual BIO in the chain. +If B is NULL nothing is done. =head1 RETURN VALUES diff --git a/engines/e_chil.c b/engines/e_chil.c index 19d29d7e62f7fc909c318f8960843f95c0ac6244..c06ab1a1e675a2c41f0ecda91fb9242fcbded098 100644 --- a/engines/e_chil.c +++ b/engines/e_chil.c @@ -656,8 +656,7 @@ static int hwcrhk_finish(ENGINE *e) goto err; } err: - if (logstream) - BIO_free(logstream); + BIO_free(logstream); hwcrhk_dso = NULL; p_hwcrhk_Init = NULL; p_hwcrhk_Finish = NULL; @@ -693,10 +692,8 @@ static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) BIO *bio = (BIO *)p; CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); - if (logstream) { - BIO_free(logstream); - logstream = NULL; - } + BIO_free(logstream); + logstream = NULL; if (CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO) > 1) logstream = bio; else diff --git a/engines/e_sureware.c b/engines/e_sureware.c index 3c7b2b26bf85d3fd6ba56fc0168a8a889deed797..5e1786ca0f962ebd6f2859c9dd4be3d17dfab5d2 100644 --- a/engines/e_sureware.c +++ b/engines/e_sureware.c @@ -404,10 +404,8 @@ static int surewarehk_ctrl(ENGINE *e, int cmd, long i, void *p, { BIO *bio = (BIO *)p; CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); - if (logstream) { - BIO_free(logstream); - logstream = NULL; - } + BIO_free(logstream); + logstream = NULL; if (CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO) > 1) logstream = bio; else @@ -596,8 +594,7 @@ static int surewarehk_finish(ENGINE *e) goto err; } err: - if (logstream) - BIO_free(logstream); + BIO_free(logstream); surewarehk_dso = NULL; p_surewarehk_Init = NULL; p_surewarehk_Finish = NULL; diff --git a/ssl/bio_ssl.c b/ssl/bio_ssl.c index 99f8b5e524ec9dc53ff91020b2e814cd77892974..11a2aadc5fdc97e3e1463201539c707753249424 100644 --- a/ssl/bio_ssl.c +++ b/ssl/bio_ssl.c @@ -503,10 +503,8 @@ BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) goto err; return (ret); err: - if (buf != NULL) - BIO_free(buf); - if (ssl != NULL) - BIO_free(ssl); + BIO_free(buf); + BIO_free(ssl); #endif return (NULL); } @@ -524,8 +522,7 @@ BIO *BIO_new_ssl_connect(SSL_CTX *ctx) goto err; return (ret); err: - if (con != NULL) - BIO_free(con); + BIO_free(con); #endif return (NULL); } diff --git a/ssl/s3_enc.c b/ssl/s3_enc.c index bcefe1276972b56673fcef714a4192e2ed7434b2..94f6dd06473e5eddc0a7a2d6756f059e238b690c 100644 --- a/ssl/s3_enc.c +++ b/ssl/s3_enc.c @@ -558,8 +558,7 @@ int ssl3_enc(SSL *s, int send) void ssl3_init_finished_mac(SSL *s) { - if (s->s3->handshake_buffer) - BIO_free(s->s3->handshake_buffer); + BIO_free(s->s3->handshake_buffer); if (s->s3->handshake_dgst) ssl3_free_digest_list(s); s->s3->handshake_buffer = BIO_new(BIO_s_mem()); diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c index 9893930eef478d48eeaf634aaced9a42cb086560..bed4a4e72d0caaecdd22b0ede37e7369f96e31e4 100644 --- a/ssl/s3_lib.c +++ b/ssl/s3_lib.c @@ -3147,9 +3147,7 @@ void ssl3_free(SSL *s) if (s->s3->tmp.ca_names != NULL) sk_X509_NAME_pop_free(s->s3->tmp.ca_names, X509_NAME_free); - if (s->s3->handshake_buffer) { - BIO_free(s->s3->handshake_buffer); - } + BIO_free(s->s3->handshake_buffer); if (s->s3->handshake_dgst) ssl3_free_digest_list(s); #ifndef OPENSSL_NO_TLSEXT @@ -3200,10 +3198,8 @@ void ssl3_clear(SSL *s) rlen = s->s3->rbuf.len; wlen = s->s3->wbuf.len; init_extra = s->s3->init_extra; - if (s->s3->handshake_buffer) { - BIO_free(s->s3->handshake_buffer); - s->s3->handshake_buffer = NULL; - } + BIO_free(s->s3->handshake_buffer); + s->s3->handshake_buffer = NULL; if (s->s3->handshake_dgst) { ssl3_free_digest_list(s); } diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index cbfe7bb416c0996e4410cf667ef37b511b8baedb..367f7a9603a4c3a00e9970c8a90ef04b72fac16c 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -877,8 +877,7 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) } if (sk != NULL) sk_X509_NAME_free(sk); - if (in != NULL) - BIO_free(in); + BIO_free(in); if (x != NULL) X509_free(x); if (ret != NULL) @@ -938,8 +937,7 @@ int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, err: ret = 0; } - if (in != NULL) - BIO_free(in); + BIO_free(in); if (x != NULL) X509_free(x); diff --git a/ssl/ssl_conf.c b/ssl/ssl_conf.c index 0fd6c1f1be8422b0ddf56c70cc15fb0241f1ba58..43821f6f37c305ad6bda37a3659b84e0d7c02e8e 100644 --- a/ssl/ssl_conf.c +++ b/ssl/ssl_conf.c @@ -438,8 +438,7 @@ static int cmd_DHParameters(SSL_CONF_CTX *cctx, const char *value) rv = SSL_set_tmp_dh(cctx->ssl, dh); end: DH_free(dh); - if (in) - BIO_free(in); + BIO_free(in); return rv > 0; } #endif diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 29bbc03e4c30d8b3bf7b31ce1378646c1d9ef155..1e9ad91c468abc97941da16a5b695ca99b21f530 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -543,9 +543,8 @@ void SSL_free(SSL *s) BIO_free(s->bbio); s->bbio = NULL; } - if (s->rbio != NULL) - BIO_free_all(s->rbio); - if ((s->wbio != NULL) && (s->wbio != s->rbio)) + BIO_free_all(s->rbio); + if (s->wbio != s->rbio) BIO_free_all(s->wbio); if (s->init_buf != NULL) @@ -621,7 +620,7 @@ void SSL_free(SSL *s) void SSL_set_rbio(SSL *s, BIO *rbio) { - if ((s->rbio != NULL) && (s->rbio != rbio)) + if (s->rbio != rbio) BIO_free_all(s->rbio); s->rbio = rbio; } @@ -637,7 +636,7 @@ void SSL_set_wbio(SSL *s, BIO *wbio) s->bbio->next_bio = NULL; } } - if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio)) + if (s->wbio != wbio && s->rbio != s->wbio) BIO_free_all(s->wbio); s->wbio = wbio; } diff --git a/ssl/ssl_rsa.c b/ssl/ssl_rsa.c index 60a68340d1ed94e81ddad9cc2fb3f12416e3043e..90fe8c8af9baef4dcf502d9f66cb6867177f146f 100644 --- a/ssl/ssl_rsa.c +++ b/ssl/ssl_rsa.c @@ -121,8 +121,7 @@ int SSL_use_certificate_file(SSL *ssl, const char *file, int type) end: if (x != NULL) X509_free(x); - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } #endif @@ -262,8 +261,7 @@ int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type) ret = SSL_use_RSAPrivateKey(ssl, rsa); RSA_free(rsa); end: - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } # endif @@ -335,8 +333,7 @@ int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type) ret = SSL_use_PrivateKey(ssl, pkey); EVP_PKEY_free(pkey); end: - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } #endif @@ -470,8 +467,7 @@ int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type) end: if (x != NULL) X509_free(x); - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } #endif @@ -552,8 +548,7 @@ int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type) ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa); RSA_free(rsa); end: - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } # endif @@ -622,8 +617,7 @@ int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) ret = SSL_CTX_use_PrivateKey(ctx, pkey); EVP_PKEY_free(pkey); end: - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } #endif @@ -726,8 +720,7 @@ int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) end: if (x != NULL) X509_free(x); - if (in != NULL) - BIO_free(in); + BIO_free(in); return (ret); } #endif @@ -991,8 +984,7 @@ int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file) OPENSSL_free(header); OPENSSL_free(extension); OPENSSL_free(serverinfo); - if (bin != NULL) - BIO_free(bin); + BIO_free(bin); return ret; } # endif /* OPENSSL_NO_STDIO */ diff --git a/ssl/ssl_task.c b/ssl/ssl_task.c index ab37cc6bef742064aea99f615678b45668b29291..d5ca89feb8a7835e4f1b3571c7e7609b002ec1d9 100644 --- a/ssl/ssl_task.c +++ b/ssl/ssl_task.c @@ -381,13 +381,9 @@ int doit(io_channel chan, SSL_CTX *s_ctx) s_ssl->rbio = NULL; s_ssl->wbio = NULL; - if (c_to_s != NULL) - BIO_free(c_to_s); - if (s_to_c != NULL) - BIO_free(s_to_c); - if (c_bio != NULL) - BIO_free(c_bio); - if (s_bio != NULL) - BIO_free(s_bio); + BIO_free(c_to_s); + BIO_free(s_to_c); + BIO_free(c_bio); + BIO_free(s_bio); return (0); } diff --git a/ssl/ssltest.c b/ssl/ssltest.c index d244ba3cd93c7815fd95cb063df9643d15d3d221..508fedd613f8f71a2f9d477a63a60fc7b83a7b27 100644 --- a/ssl/ssltest.c +++ b/ssl/ssltest.c @@ -1798,8 +1798,7 @@ int main(int argc, char *argv[]) SSL_CONF_CTX_free(c_cctx); sk_OPENSSL_STRING_free(conf_args); - if (bio_stdout != NULL) - BIO_free(bio_stdout); + BIO_free(bio_stdout); #ifndef OPENSSL_NO_RSA free_tmp_rsa(); @@ -1812,8 +1811,7 @@ int main(int argc, char *argv[]) ERR_remove_thread_state(NULL); EVP_cleanup(); CRYPTO_mem_leaks(bio_err); - if (bio_err != NULL) - BIO_free(bio_err); + BIO_free(bio_err); EXIT(ret); } @@ -2173,18 +2171,12 @@ int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count, err: ERR_print_errors(bio_err); - if (server) - BIO_free(server); - if (server_io) - BIO_free(server_io); - if (client) - BIO_free(client); - if (client_io) - BIO_free(client_io); - if (s_ssl_bio) - BIO_free(s_ssl_bio); - if (c_ssl_bio) - BIO_free(c_ssl_bio); + BIO_free(server); + BIO_free(server_io); + BIO_free(client); + BIO_free(client_io); + BIO_free(s_ssl_bio); + BIO_free(c_ssl_bio); return ret; } @@ -2468,14 +2460,10 @@ int doit(SSL *s_ssl, SSL *c_ssl, long count) c_ssl->wbio = NULL; } - if (c_to_s != NULL) - BIO_free(c_to_s); - if (s_to_c != NULL) - BIO_free(s_to_c); - if (c_bio != NULL) - BIO_free_all(c_bio); - if (s_bio != NULL) - BIO_free_all(s_bio); + BIO_free(c_to_s); + BIO_free(s_to_c); + BIO_free_all(c_bio); + BIO_free_all(s_bio); if (cbuf) OPENSSL_free(cbuf);