[openssl-commits] [openssl] master update

Rich Salz rsalz at openssl.org
Wed Mar 25 15:31:52 UTC 2015


The branch master has been updated
       via  ca3a82c3b364e1e584546f0f3bbb938b0b472580 (commit)
      from  2011b169fa90edd4d986e7dbbd3d64587d316a22 (commit)


- Log -----------------------------------------------------------------
commit ca3a82c3b364e1e584546f0f3bbb938b0b472580
Author: Rich Salz <rsalz at openssl.org>
Date:   Wed Mar 25 11:31:18 2015 -0400

    free NULL cleanup
    
    This commit handles BIO_ACCEPT_free BIO_CB_FREE BIO_CONNECT_free
    BIO_free BIO_free_all BIO_vfree
    
    Reviewed-by: Matt Caswell <matt at openssl.org>

-----------------------------------------------------------------------

Summary of changes:
 apps/apps.c              | 12 ++++--------
 apps/asn1pars.c          |  9 +++------
 apps/ca.c                |  3 +--
 apps/ciphers.c           |  3 +--
 apps/crl2p7.c            |  9 +++------
 apps/dgst.c              |  6 ++----
 apps/dh.c                |  6 ++----
 apps/dhparam.c           |  6 ++----
 apps/dsa.c               |  6 ++----
 apps/dsaparam.c          |  6 ++----
 apps/ec.c                |  6 ++----
 apps/ecparam.c           |  6 ++----
 apps/enc.c               | 15 +++++----------
 apps/engine.c            |  3 +--
 apps/errstr.c            |  3 +--
 apps/gendh.c             |  3 +--
 apps/gendsa.c            |  6 ++----
 apps/genpkey.c           |  3 +--
 apps/genrsa.c            |  3 +--
 apps/ocsp.c              |  3 +--
 apps/openssl.c           |  6 ++----
 apps/passwd.c            |  6 ++----
 apps/pkcs7.c             |  6 ++----
 apps/rand.c              |  3 +--
 apps/rsa.c               |  3 +--
 apps/s_client.c          | 12 ++++--------
 apps/s_server.c          | 25 ++++++++-----------------
 apps/sess_id.c           |  6 ++----
 apps/ts.c                |  2 +-
 crypto/asn1/asn_mime.c   |  3 +--
 crypto/asn1/bio_asn1.c   |  4 ++--
 crypto/asn1/bio_ndef.c   |  3 +--
 crypto/bio/bio_lib.c     |  3 +--
 crypto/bio/bss_acpt.c    | 12 ++++--------
 crypto/bio/bss_bio.c     | 12 ++++--------
 crypto/bio/bss_conn.c    |  6 ++----
 crypto/cms/cms_lib.c     |  3 +--
 crypto/cms/cms_sd.c      |  3 +--
 crypto/cms/cms_smime.c   |  8 +++-----
 crypto/dsa/dsatest.c     |  6 ++----
 crypto/ecdsa/ecdsatest.c |  3 +--
 crypto/ocsp/ocsp_ht.c    |  3 +--
 crypto/pkcs7/pk7_doit.c  | 29 ++++++++++-------------------
 crypto/srp/srp_vfy.c     |  3 +--
 crypto/threads/mttest.c  | 14 +++++---------
 crypto/x509/by_file.c    |  6 ++----
 demos/b64.c              | 12 ++++--------
 demos/bio/saccept.c      |  6 ++----
 demos/bio/server-arg.c   |  3 +--
 demos/bio/server-conf.c  |  3 +--
 demos/cms/cms_comp.c     |  6 ++----
 demos/cms/cms_ddec.c     | 12 ++++--------
 demos/cms/cms_dec.c      |  9 +++------
 demos/cms/cms_denc.c     | 12 ++++--------
 demos/cms/cms_enc.c      |  9 +++------
 demos/cms/cms_sign.c     |  9 +++------
 demos/cms/cms_sign2.c    |  9 +++------
 demos/cms/cms_uncomp.c   |  6 ++----
 demos/cms/cms_ver.c      |  9 +++------
 demos/smime/smdec.c      |  9 +++------
 demos/smime/smenc.c      |  9 +++------
 demos/smime/smsign.c     |  9 +++------
 demos/smime/smsign2.c    |  9 +++------
 demos/smime/smver.c      |  9 +++------
 doc/crypto/BIO_new.pod   |  5 ++++-
 engines/e_chil.c         |  9 +++------
 engines/e_sureware.c     |  9 +++------
 ssl/bio_ssl.c            |  9 +++------
 ssl/s3_enc.c             |  3 +--
 ssl/s3_lib.c             | 10 +++-------
 ssl/ssl_cert.c           |  6 ++----
 ssl/ssl_conf.c           |  3 +--
 ssl/ssl_lib.c            |  9 ++++-----
 ssl/ssl_rsa.c            | 24 ++++++++----------------
 ssl/ssl_task.c           | 12 ++++--------
 ssl/ssltest.c            | 36 ++++++++++++------------------------
 76 files changed, 202 insertions(+), 390 deletions(-)

diff --git a/apps/apps.c b/apps/apps.c
index 233d382..1dcaabf 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 da95011..1576f1c 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 b498b0a..89bece8 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 803b021..6c7ff01 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 0763817..ab0c3d6 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 95e5fa3..ac3b583 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 a921633..1b653f5 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 12a2be6..fc5962a 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 8d085bc..1ea0d73 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 fc1c817..f63ecb2 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 b04dada..2064723 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 06ac77b..d417747 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 1739b7e..b95a6a2 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 8a1e746..5386465 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 c2d4fde..668c5f3 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 6102b79..904bcf3 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 d330a01..8288eb9 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 fc19a92..5b7f433 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 1b06c82..cf60219 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 83a7175..9538096 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 e070a44..e93aed7 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 798a6d5..2814b32 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 643507f..1b07c02 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 e159da3..45f16b9 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 ac4a3c4..2f3f871 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 cdea322..0874983 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 c3884d2..37c40cb 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 9400af9..53ccbb3 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 fb77d6a..4c32ada 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 e96fb02..e810345 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 0b4fd1d..d4be23c 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 4a73ca9..1018787 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 11e0142..a5d8680 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 5aa06cf..72f7bd2 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 d629a37..c6bb3d6 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 c7f57f1..e95b4b3 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 7e1c1e8..6d2a0e8 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 b8ed1a1..c45d30e 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 6f6f20d..f491ec9 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 bf47816..a5d40f1 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 c2132da..346ccd0 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 aca0d48..4a06a8e 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 f77326b..b7c66a3 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 9d83a8f..82b9a77 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 ea3784c..f6f8df2 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 43a0730..bc1c90c 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 d8ed2a6..fcc6956 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 8c75029..505d98b 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 7ba54db..4f65227 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 a09bc93..5355839 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 059152f..e117d37 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 37ac97f..7247e57 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 3291eac..e9782d7 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 c86a5fd..8526717 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 e8ecb48..4395e6b 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 4bf85d1..9f2cff0 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 7e98a51..23c6eb8 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 392f4b4..8d45834 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 ca93551..4227531 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 6814d51..b50f8df 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 18bf7b1..5a85537 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 c7bf86d..6b9dfdd 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 a116094..5d9de35 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 21937df..4088d3c 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 2a245fc..76679f3 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<type>.
 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<a> 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<a> is NULL nothing is done.
 
 =head1 RETURN VALUES
 
diff --git a/engines/e_chil.c b/engines/e_chil.c
index 19d29d7..c06ab1a 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 3c7b2b2..5e1786c 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 99f8b5e..11a2aad 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 bcefe12..94f6dd0 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 9893930..bed4a4e 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 cbfe7bb..367f7a9 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 0fd6c1f..43821f6 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 29bbc03..1e9ad91 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 60a6834..90fe8c8 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 ab37cc6..d5ca89f 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 d244ba3..508fedd 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);


More information about the openssl-commits mailing list