From: jsing Date: Wed, 7 Feb 2018 04:57:06 +0000 (+0000) Subject: Remove guards around *_free() calls since these functions handle NULL. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4fe8ecdd3e465327690be8f444c310fb6ffded9c;p=openbsd Remove guards around *_free() calls since these functions handle NULL. --- diff --git a/usr.bin/openssl/asn1pars.c b/usr.bin/openssl/asn1pars.c index fe66b359373..0f432c246bc 100644 --- a/usr.bin/openssl/asn1pars.c +++ b/usr.bin/openssl/asn1pars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1pars.c,v 1.7 2017/01/20 08:57:11 deraadt Exp $ */ +/* $OpenBSD: asn1pars.c,v 1.8 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -416,8 +416,7 @@ end: if (ret != 0) ERR_print_errors(bio_err); BUF_MEM_free(buf); - if (at != NULL) - ASN1_TYPE_free(at); + ASN1_TYPE_free(at); sk_OPENSSL_STRING_free(asn1pars_config.osk); OBJ_cleanup(); diff --git a/usr.bin/openssl/dh.c b/usr.bin/openssl/dh.c index eb51b4b12fb..b8d4054e563 100644 --- a/usr.bin/openssl/dh.c +++ b/usr.bin/openssl/dh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh.c,v 1.9 2017/01/20 08:57:11 deraadt Exp $ */ +/* $OpenBSD: dh.c,v 1.10 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -290,10 +290,8 @@ dh_main(int argc, char **argv) end: BIO_free(in); - if (out != NULL) - BIO_free_all(out); - if (dh != NULL) - DH_free(dh); + BIO_free_all(out); + DH_free(dh); return (ret); } diff --git a/usr.bin/openssl/dhparam.c b/usr.bin/openssl/dhparam.c index 7c3bfb44c8d..13e8a49a1cd 100644 --- a/usr.bin/openssl/dhparam.c +++ b/usr.bin/openssl/dhparam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhparam.c,v 1.9 2017/01/20 08:57:11 deraadt Exp $ */ +/* $OpenBSD: dhparam.c,v 1.10 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -292,8 +292,7 @@ dhparam_main(int argc, char **argv) BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num); if (!dsa || !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL, &cb)) { - if (dsa) - DSA_free(dsa); + DSA_free(dsa); ERR_print_errors(bio_err); goto end; } @@ -469,10 +468,8 @@ dhparam_main(int argc, char **argv) end: BIO_free(in); - if (out != NULL) - BIO_free_all(out); - if (dh != NULL) - DH_free(dh); + BIO_free_all(out); + DH_free(dh); return (ret); } diff --git a/usr.bin/openssl/dsa.c b/usr.bin/openssl/dsa.c index 5e0301c7342..34b29eee3ea 100644 --- a/usr.bin/openssl/dsa.c +++ b/usr.bin/openssl/dsa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa.c,v 1.9 2017/01/20 08:57:11 deraadt Exp $ */ +/* $OpenBSD: dsa.c,v 1.10 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -362,10 +362,8 @@ dsa_main(int argc, char **argv) ret = 0; end: BIO_free(in); - if (out != NULL) - BIO_free_all(out); - if (dsa != NULL) - DSA_free(dsa); + BIO_free_all(out); + DSA_free(dsa); free(passin); free(passout); diff --git a/usr.bin/openssl/dsaparam.c b/usr.bin/openssl/dsaparam.c index 46efd5d4536..dfafc2e077a 100644 --- a/usr.bin/openssl/dsaparam.c +++ b/usr.bin/openssl/dsaparam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsaparam.c,v 1.8 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: dsaparam.c,v 1.9 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -340,10 +340,8 @@ dsaparam_main(int argc, char **argv) end: BIO_free(in); - if (out != NULL) - BIO_free_all(out); - if (dsa != NULL) - DSA_free(dsa); + BIO_free_all(out); + DSA_free(dsa); return (ret); } diff --git a/usr.bin/openssl/ec.c b/usr.bin/openssl/ec.c index e557990cb9b..7ef2ac8de11 100644 --- a/usr.bin/openssl/ec.c +++ b/usr.bin/openssl/ec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec.c,v 1.9 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: ec.c,v 1.10 2018/02/07 04:57:06 jsing Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -394,10 +394,8 @@ ec_main(int argc, char **argv) ret = 0; end: BIO_free(in); - if (out) - BIO_free_all(out); - if (eckey) - EC_KEY_free(eckey); + BIO_free_all(out); + EC_KEY_free(eckey); free(passin); free(passout); diff --git a/usr.bin/openssl/enc.c b/usr.bin/openssl/enc.c index 195dc2fc44f..7f06fcc0644 100644 --- a/usr.bin/openssl/enc.c +++ b/usr.bin/openssl/enc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: enc.c,v 1.12 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: enc.c,v 1.13 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -722,8 +722,7 @@ end: free(strbuf); free(buff); BIO_free(in); - if (out != NULL) - BIO_free_all(out); + BIO_free_all(out); BIO_free(benc); BIO_free(b64); #ifdef ZLIB diff --git a/usr.bin/openssl/gendh.c b/usr.bin/openssl/gendh.c index 7c037f44e16..9cbbe42b19c 100644 --- a/usr.bin/openssl/gendh.c +++ b/usr.bin/openssl/gendh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gendh.c,v 1.8 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: gendh.c,v 1.9 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -189,10 +189,8 @@ gendh_main(int argc, char **argv) end: if (ret != 0) ERR_print_errors(bio_err); - if (out != NULL) - BIO_free_all(out); - if (dh != NULL) - DH_free(dh); + BIO_free_all(out); + DH_free(dh); return (ret); } diff --git a/usr.bin/openssl/gendsa.c b/usr.bin/openssl/gendsa.c index 5aeb294e7f1..1e6a6061e18 100644 --- a/usr.bin/openssl/gendsa.c +++ b/usr.bin/openssl/gendsa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gendsa.c,v 1.8 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: gendsa.c,v 1.9 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -206,10 +206,8 @@ end: if (ret != 0) ERR_print_errors(bio_err); BIO_free(in); - if (out != NULL) - BIO_free_all(out); - if (dsa != NULL) - DSA_free(dsa); + BIO_free_all(out); + DSA_free(dsa); free(passout); return (ret); diff --git a/usr.bin/openssl/genpkey.c b/usr.bin/openssl/genpkey.c index cae7eacd4ed..f161c55f7b1 100644 --- a/usr.bin/openssl/genpkey.c +++ b/usr.bin/openssl/genpkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: genpkey.c,v 1.9 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: genpkey.c,v 1.10 2018/02/07 04:57:06 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006 */ @@ -238,12 +238,9 @@ bad: ret = 0; end: - if (pkey) - EVP_PKEY_free(pkey); - if (ctx) - EVP_PKEY_CTX_free(ctx); - if (out) - BIO_free_all(out); + EVP_PKEY_free(pkey); + EVP_PKEY_CTX_free(ctx); + BIO_free_all(out); BIO_free(in); free(pass); @@ -285,10 +282,8 @@ 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; } @@ -332,8 +327,7 @@ 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; } diff --git a/usr.bin/openssl/genrsa.c b/usr.bin/openssl/genrsa.c index 4fa5747b286..2780b74a03e 100644 --- a/usr.bin/openssl/genrsa.c +++ b/usr.bin/openssl/genrsa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: genrsa.c,v 1.9 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: genrsa.c,v 1.10 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -234,13 +234,11 @@ bad: ret = 0; err: - if (bn) - BN_free(bn); - if (rsa) - RSA_free(rsa); - if (out) - BIO_free_all(out); + BN_free(bn); + RSA_free(rsa); + BIO_free_all(out); free(passout); + if (ret != 0) ERR_print_errors(bio_err); diff --git a/usr.bin/openssl/pkeyutl.c b/usr.bin/openssl/pkeyutl.c index dd52e93dfa4..659c2b2916c 100644 --- a/usr.bin/openssl/pkeyutl.c +++ b/usr.bin/openssl/pkeyutl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pkeyutl.c,v 1.12 2018/01/28 09:21:34 inoguchi Exp $ */ +/* $OpenBSD: pkeyutl.c,v 1.13 2018/02/07 04:57:06 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -310,8 +310,7 @@ pkeyutl_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); free(buf_in); diff --git a/usr.bin/openssl/rand.c b/usr.bin/openssl/rand.c index 04105bc46ec..6e4517ac0b6 100644 --- a/usr.bin/openssl/rand.c +++ b/usr.bin/openssl/rand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rand.c,v 1.11 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: rand.c,v 1.12 2018/02/07 04:57:06 jsing Exp $ */ /* ==================================================================== * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. * @@ -178,8 +178,7 @@ rand_main(int argc, char **argv) err: ERR_print_errors(bio_err); - if (out) - BIO_free_all(out); + BIO_free_all(out); return (ret); } diff --git a/usr.bin/openssl/s_client.c b/usr.bin/openssl/s_client.c index f81d1a61bbf..158992aa04c 100644 --- a/usr.bin/openssl/s_client.c +++ b/usr.bin/openssl/s_client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_client.c,v 1.33 2017/08/12 21:04:33 jsing Exp $ */ +/* $OpenBSD: s_client.c,v 1.34 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1212,15 +1212,11 @@ end: print_stuff(bio_c_out, con, 1); SSL_free(con); } - if (ctx != NULL) - SSL_CTX_free(ctx); - if (cert) - X509_free(cert); - if (key) - EVP_PKEY_free(key); + SSL_CTX_free(ctx); + X509_free(cert); + EVP_PKEY_free(key); free(pass); - if (vpm) - X509_VERIFY_PARAM_free(vpm); + X509_VERIFY_PARAM_free(vpm); freezero(cbuf, BUFSIZZ); freezero(sbuf, BUFSIZZ); freezero(mbuf, BUFSIZZ); @@ -1405,8 +1401,7 @@ print_stuff(BIO * bio, SSL * s, int full) } } BIO_printf(bio, "---\n"); - if (peer != NULL) - X509_free(peer); + X509_free(peer); /* flush, or debugging output gets mixed with http response */ (void) BIO_flush(bio); } diff --git a/usr.bin/openssl/s_server.c b/usr.bin/openssl/s_server.c index ccab5b32804..140ab923519 100644 --- a/usr.bin/openssl/s_server.c +++ b/usr.bin/openssl/s_server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_server.c,v 1.28 2018/01/28 09:21:34 inoguchi Exp $ */ +/* $OpenBSD: s_server.c,v 1.29 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1199,29 +1199,20 @@ bad: print_stats(bio_s_out, ctx); ret = 0; end: - if (ctx != NULL) - SSL_CTX_free(ctx); - if (s_cert) - X509_free(s_cert); - if (s_dcert) - X509_free(s_dcert); - if (s_key) - EVP_PKEY_free(s_key); - if (s_dkey) - EVP_PKEY_free(s_dkey); + SSL_CTX_free(ctx); + X509_free(s_cert); + X509_free(s_dcert); + EVP_PKEY_free(s_key); + EVP_PKEY_free(s_dkey); free(pass); free(dpass); - if (vpm) - X509_VERIFY_PARAM_free(vpm); + X509_VERIFY_PARAM_free(vpm); free(tlscstatp.host); free(tlscstatp.port); free(tlscstatp.path); - if (ctx2 != NULL) - SSL_CTX_free(ctx2); - if (s_cert2) - X509_free(s_cert2); - if (s_key2) - EVP_PKEY_free(s_key2); + SSL_CTX_free(ctx2); + X509_free(s_cert2); + EVP_PKEY_free(s_key2); free(alpn_ctx.data); if (bio_s_out != NULL) { BIO_free(bio_s_out); @@ -1959,8 +1950,7 @@ err: BIO_printf(bio_s_out, "ACCEPT\n"); free(buf); - if (io != NULL) - BIO_free_all(io); + BIO_free_all(io); /* if (ssl_bio != NULL) BIO_free(ssl_bio);*/ return (ret); } diff --git a/usr.bin/openssl/s_time.c b/usr.bin/openssl/s_time.c index a533679776b..e8e8a273a7f 100644 --- a/usr.bin/openssl/s_time.c +++ b/usr.bin/openssl/s_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_time.c,v 1.21 2018/02/06 02:40:29 tb Exp $ */ +/* $OpenBSD: s_time.c,v 1.22 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -473,8 +473,7 @@ next: ret = 0; end: - if (scon != NULL) - SSL_free(scon); + SSL_free(scon); if (tm_ctx != NULL) { SSL_CTX_free(tm_ctx); diff --git a/usr.bin/openssl/smime.c b/usr.bin/openssl/smime.c index 847ee133b68..4222e24bc1b 100644 --- a/usr.bin/openssl/smime.c +++ b/usr.bin/openssl/smime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smime.c,v 1.8 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: smime.c,v 1.9 2018/02/07 04:57:06 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. */ @@ -625,12 +625,9 @@ end: ERR_print_errors(bio_err); sk_X509_pop_free(encerts, X509_free); sk_X509_pop_free(other, X509_free); - if (vpm) - X509_VERIFY_PARAM_free(vpm); - if (sksigners) - sk_OPENSSL_STRING_free(sksigners); - if (skkeys) - sk_OPENSSL_STRING_free(skkeys); + X509_VERIFY_PARAM_free(vpm); + sk_OPENSSL_STRING_free(sksigners); + sk_OPENSSL_STRING_free(skkeys); X509_STORE_free(store); X509_free(cert); X509_free(recip); diff --git a/usr.bin/openssl/x509.c b/usr.bin/openssl/x509.c index f43b0156849..8d3dc07090e 100644 --- a/usr.bin/openssl/x509.c +++ b/usr.bin/openssl/x509.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509.c,v 1.14 2017/01/20 08:57:12 deraadt Exp $ */ +/* $OpenBSD: x509.c,v 1.15 2018/02/07 04:57:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -916,8 +916,7 @@ end: X509_free(xca); EVP_PKEY_free(Upkey); EVP_PKEY_free(CApkey); - if (sigopts) - sk_OPENSSL_STRING_free(sigopts); + sk_OPENSSL_STRING_free(sigopts); X509_REQ_free(rq); ASN1_INTEGER_free(sno); sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);