diff options
author | Rich Salz <rsalz@openssl.org> | 2015-05-01 20:37:16 +0200 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-05-01 20:37:16 +0200 |
commit | 25aaa98aa249d26391c1994d2de449562c8b8b99 (patch) | |
tree | 6f83efd87fa9fd832e8a456e9686143a29f1dab3 /apps | |
parent | Remove goto inside an if(0) block (diff) | |
download | openssl-25aaa98aa249d26391c1994d2de449562c8b8b99.tar.xz openssl-25aaa98aa249d26391c1994d2de449562c8b8b99.zip |
free NULL cleanup -- coda
After the finale, the "real" final part. :) Do a recursive grep with
"-B1 -w [a-zA-Z0-9_]*_free" to see if any of the preceeding lines are
an "if NULL" check that can be removed.
Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/apps.c | 18 | ||||
-rw-r--r-- | apps/asn1pars.c | 6 | ||||
-rw-r--r-- | apps/ca.c | 23 | ||||
-rw-r--r-- | apps/ciphers.c | 2 | ||||
-rw-r--r-- | apps/cms.c | 27 | ||||
-rw-r--r-- | apps/dgst.c | 9 | ||||
-rw-r--r-- | apps/engine.c | 3 | ||||
-rw-r--r-- | apps/genrsa.c | 6 | ||||
-rw-r--r-- | apps/ocsp.c | 3 | ||||
-rw-r--r-- | apps/openssl.c | 9 | ||||
-rw-r--r-- | apps/pkcs12.c | 3 | ||||
-rw-r--r-- | apps/req.c | 8 | ||||
-rw-r--r-- | apps/s_cb.c | 6 | ||||
-rw-r--r-- | apps/s_server.c | 34 | ||||
-rw-r--r-- | apps/sess_id.c | 3 | ||||
-rw-r--r-- | apps/smime.c | 6 | ||||
-rw-r--r-- | apps/srp.c | 7 | ||||
-rw-r--r-- | apps/x509.c | 3 |
18 files changed, 61 insertions, 115 deletions
diff --git a/apps/apps.c b/apps/apps.c index f2a17a4633..1b76dbf825 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -592,12 +592,9 @@ int load_cert_crl_http(const char *url, X509 **pcert, X509_CRL **pcrl) } err: - if (host) - OPENSSL_free(host); - if (path) - OPENSSL_free(path); - if (port) - OPENSSL_free(port); + OPENSSL_free(host); + OPENSSL_free(path); + OPENSSL_free(port); if (bio) BIO_free_all(bio); OCSP_REQ_CTX_free(rctx); @@ -660,8 +657,7 @@ X509 *load_cert(const char *file, int format, BIO_printf(bio_err, "unable to load certificate\n"); ERR_print_errors(bio_err); } - if (cert != NULL) - BIO_free(cert); + BIO_free(cert); return (x); } @@ -761,8 +757,7 @@ EVP_PKEY *load_key(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(bio_err, "unable to load %s\n", key_descrip); ERR_print_errors(bio_err); @@ -849,8 +844,7 @@ EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin, pkey = b2i_PublicKey_bio(key); #endif end: - if (key != NULL) - BIO_free(key); + BIO_free(key); if (pkey == NULL) BIO_printf(bio_err, "unable to load %s\n", key_descrip); return (pkey); diff --git a/apps/asn1pars.c b/apps/asn1pars.c index 01a50f4e5d..61bdeabe5b 100644 --- a/apps/asn1pars.c +++ b/apps/asn1pars.c @@ -319,15 +319,13 @@ int asn1parse_main(int argc, char **argv) BIO_free(b64); if (ret != 0) ERR_print_errors(bio_err); - if (buf != NULL) - BUF_MEM_free(buf); + BUF_MEM_free(buf); OPENSSL_free(name); OPENSSL_free(header); if (strictpem) OPENSSL_free(str); ASN1_TYPE_free(at); - if (osk != NULL) - sk_OPENSSL_STRING_free(osk); + sk_OPENSSL_STRING_free(osk); OBJ_cleanup(); return (ret); } @@ -514,10 +514,8 @@ end_of_options: errorline, configfile); goto end; } - if (tofree) { - OPENSSL_free(tofree); - tofree = NULL; - } + OPENSSL_free(tofree); + tofree = NULL; /* Lets get the config section we are using */ if (section == NULL) { @@ -1331,8 +1329,7 @@ end_of_options: /*****************************************************************/ ret = 0; end: - if (tofree) - OPENSSL_free(tofree); + OPENSSL_free(tofree); BIO_free_all(Cout); BIO_free_all(Sout); BIO_free_all(out); @@ -1342,13 +1339,12 @@ end_of_options: if (ret) ERR_print_errors(bio_err); app_RAND_write_file(randfile); - if (free_key && key) + if (free_key) OPENSSL_free(key); BN_free(serial); BN_free(crlnumber); free_index(db); - if (sigopts) - sk_OPENSSL_STRING_free(sigopts); + sk_OPENSSL_STRING_free(sigopts); EVP_PKEY_free(pkey); X509_free(x509); X509_CRL_free(crl); @@ -2000,8 +1996,7 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, ok = 1; end: for (i = 0; i < DB_NUMBER; i++) - if (row[i] != NULL) - OPENSSL_free(row[i]); + OPENSSL_free(row[i]); X509_NAME_free(CAname); X509_NAME_free(subject); @@ -2159,10 +2154,8 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, ext_copy, 0); end: X509_REQ_free(req); - if (parms != NULL) - CONF_free(parms); - if (spki != NULL) - NETSCAPE_SPKI_free(spki); + CONF_free(parms); + NETSCAPE_SPKI_free(spki); X509_NAME_ENTRY_free(ne); return (ok); diff --git a/apps/ciphers.c b/apps/ciphers.c index 3d84a2b14e..232fd602fd 100644 --- a/apps/ciphers.c +++ b/apps/ciphers.c @@ -214,7 +214,7 @@ int ciphers_main(int argc, char **argv) err: ERR_print_errors(bio_err); end: - if (use_supported && sk) + if (use_supported) sk_SSL_CIPHER_free(sk); SSL_CTX_free(ctx); SSL_free(ssl); diff --git a/apps/cms.c b/apps/cms.c index 25e3ad62fd..79d0b8f5d6 100644 --- a/apps/cms.c +++ b/apps/cms.c @@ -1117,20 +1117,15 @@ int cms_main(int argc, char **argv) sk_X509_pop_free(encerts, X509_free); sk_X509_pop_free(other, X509_free); X509_VERIFY_PARAM_free(vpm); - if (sksigners) - sk_OPENSSL_STRING_free(sksigners); - if (skkeys) - sk_OPENSSL_STRING_free(skkeys); + sk_OPENSSL_STRING_free(sksigners); + sk_OPENSSL_STRING_free(skkeys); OPENSSL_free(secret_key); OPENSSL_free(secret_keyid); OPENSSL_free(pwri_tmp); ASN1_OBJECT_free(econtent_type); - if (rr) - CMS_ReceiptRequest_free(rr); - if (rr_to) - sk_OPENSSL_STRING_free(rr_to); - if (rr_from) - sk_OPENSSL_STRING_free(rr_from); + CMS_ReceiptRequest_free(rr); + sk_OPENSSL_STRING_free(rr_to); + sk_OPENSSL_STRING_free(rr_from); for (key_param = key_first; key_param;) { cms_key_param *tparam; sk_OPENSSL_STRING_free(key_param->param); @@ -1247,8 +1242,7 @@ static void receipt_request_print(CMS_ContentInfo *cms) BIO_puts(bio_err, " Receipts To:\n"); gnames_stack_print(rto); } - if (rr) - CMS_ReceiptRequest_free(rr); + CMS_ReceiptRequest_free(rr); } } @@ -1280,12 +1274,9 @@ static STACK_OF(GENERAL_NAMES) *make_names_stack(STACK_OF(OPENSSL_STRING) *ns) return ret; err: - if (ret) - sk_GENERAL_NAMES_pop_free(ret, GENERAL_NAMES_free); - if (gens) - GENERAL_NAMES_free(gens); - if (gen) - GENERAL_NAME_free(gen); + sk_GENERAL_NAMES_pop_free(ret, GENERAL_NAMES_free); + GENERAL_NAMES_free(gens); + GENERAL_NAME_free(gen); return NULL; } diff --git a/apps/dgst.c b/apps/dgst.c index a679cb9fe8..5d23492779 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -443,14 +443,11 @@ int dgst_main(int argc, char **argv) end: OPENSSL_clear_free(buf, BUFSIZE); BIO_free(in); - if (passin) - OPENSSL_free(passin); + OPENSSL_free(passin); BIO_free_all(out); EVP_PKEY_free(sigkey); - if (sigopts) - sk_OPENSSL_STRING_free(sigopts); - if (macopts) - sk_OPENSSL_STRING_free(macopts); + sk_OPENSSL_STRING_free(sigopts); + sk_OPENSSL_STRING_free(macopts); OPENSSL_free(sigbuf); BIO_free(bmd); return (ret); diff --git a/apps/engine.c b/apps/engine.c index c7c0aafd75..832cb0afaa 100644 --- a/apps/engine.c +++ b/apps/engine.c @@ -261,8 +261,7 @@ static int util_verbose(ENGINE *e, int verbose, BIO *out, const char *indent) BIO_printf(out, "\n"); ret = 1; err: - if (cmds) - sk_OPENSSL_STRING_pop_free(cmds, identity); + sk_OPENSSL_STRING_pop_free(cmds, identity); OPENSSL_free(name); OPENSSL_free(desc); return ret; diff --git a/apps/genrsa.c b/apps/genrsa.c index a5ab658f96..e09e576c8b 100644 --- a/apps/genrsa.c +++ b/apps/genrsa.c @@ -198,10 +198,8 @@ int genrsa_main(int argc, char **argv) if (hexe && dece) { BIO_printf(bio_err, "e is %s (0x%s)\n", dece, hexe); } - if (hexe) - OPENSSL_free(hexe); - if (dece) - OPENSSL_free(dece); + OPENSSL_free(hexe); + OPENSSL_free(dece); { PW_CB_DATA cb_data; cb_data.password = passout; diff --git a/apps/ocsp.c b/apps/ocsp.c index d4ea019650..d4538a8600 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -917,8 +917,7 @@ static void make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, NULL); goto end; } - if (ca_id) - OCSP_CERTID_free(ca_id); + OCSP_CERTID_free(ca_id); ca_id = OCSP_cert_to_id(cert_id_md, NULL, ca); /* Is this request about our CA? */ diff --git a/apps/openssl.c b/apps/openssl.c index c6b048a90d..b71f3d19f5 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -511,12 +511,9 @@ int main(int argc, char *argv[]) end: OPENSSL_free(copied_argv); OPENSSL_free(to_free); - if (config != NULL) { - NCONF_free(config); - config = NULL; - } - if (prog != NULL) - lh_FUNCTION_free(prog); + NCONF_free(config); + config = NULL; + lh_FUNCTION_free(prog); OPENSSL_free(arg.argv); BIO_free(bio_in); diff --git a/apps/pkcs12.c b/apps/pkcs12.c index 4c62392e0b..0a4ee3ed10 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -554,8 +554,7 @@ int pkcs12_main(int argc, char **argv) app_RAND_write_file(NULL); BIO_free(in); BIO_free_all(out); - if (canames) - sk_OPENSSL_STRING_free(canames); + sk_OPENSSL_STRING_free(canames); OPENSSL_free(passin); OPENSSL_free(passout); return (ret); diff --git a/apps/req.c b/apps/req.c index e8e18ecdde..b9dc35cbf8 100644 --- a/apps/req.c +++ b/apps/req.c @@ -872,16 +872,14 @@ int req_main(int argc, char **argv) if (ret) { ERR_print_errors(bio_err); } - if ((req_conf != NULL) && (req_conf != config)) + if (req_conf != config) NCONF_free(req_conf); BIO_free(in); BIO_free_all(out); EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(genctx); - if (pkeyopts) - sk_OPENSSL_STRING_free(pkeyopts); - if (sigopts) - sk_OPENSSL_STRING_free(sigopts); + sk_OPENSSL_STRING_free(pkeyopts); + sk_OPENSSL_STRING_free(sigopts); #ifndef OPENSSL_NO_ENGINE ENGINE_free(gen_eng); #endif diff --git a/apps/s_cb.c b/apps/s_cb.c index 1f2d371952..13a3a25652 100644 --- a/apps/s_cb.c +++ b/apps/s_cb.c @@ -1202,6 +1202,9 @@ static int ssl_excert_prepend(SSL_EXCERT **pexc) void ssl_excert_free(SSL_EXCERT *exc) { SSL_EXCERT *curr; + + if (!exc) + return; while (exc) { X509_free(exc->cert); EVP_PKEY_free(exc->key); @@ -1311,8 +1314,7 @@ int args_excert(int opt, SSL_EXCERT **pexc) err: ERR_print_errors(bio_err); - if (exc) - ssl_excert_free(exc); + ssl_excert_free(exc); *pexc = NULL; return 0; } diff --git a/apps/s_server.c b/apps/s_server.c index 5fb275d0d8..fead620210 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -475,8 +475,7 @@ static int ebcdic_free(BIO *a) { if (a == NULL) return (0); - if (a->ptr != NULL) - OPENSSL_free(a->ptr); + OPENSSL_free(a->ptr); a->ptr = NULL; a->init = 0; a->flags = 0; @@ -725,12 +724,9 @@ static int cert_status_cb(SSL *s, void *arg) OPENSSL_free(port); X509_email_free(aia); } - if (id) - OCSP_CERTID_free(id); - if (req) - OCSP_REQUEST_free(req); - if (resp) - OCSP_RESPONSE_free(resp); + OCSP_CERTID_free(id); + OCSP_REQUEST_free(req); + OCSP_RESPONSE_free(resp); return ret; err: ret = SSL_TLSEXT_ERR_ALERT_FATAL; @@ -1928,30 +1924,22 @@ int s_server_main(int argc, char *argv[]) EVP_PKEY_free(s_dkey); sk_X509_pop_free(s_chain, X509_free); sk_X509_pop_free(s_dchain, X509_free); - if (pass) - OPENSSL_free(pass); - if (dpass) - OPENSSL_free(dpass); + OPENSSL_free(pass); + OPENSSL_free(dpass); X509_VERIFY_PARAM_free(vpm); free_sessions(); #ifndef OPENSSL_NO_TLSEXT - if (tlscstatp.host) - OPENSSL_free(tlscstatp.host); - if (tlscstatp.port) - OPENSSL_free(tlscstatp.port); - if (tlscstatp.path) - OPENSSL_free(tlscstatp.path); - if (ctx2 != NULL) + OPENSSL_free(tlscstatp.host); + OPENSSL_free(tlscstatp.port); + OPENSSL_free(tlscstatp.path); SSL_CTX_free(ctx2); X509_free(s_cert2); EVP_PKEY_free(s_key2); BIO_free(serverinfo_in); # ifndef OPENSSL_NO_NEXTPROTONEG - if (next_proto.data) - OPENSSL_free(next_proto.data); + OPENSSL_free(next_proto.data); # endif - if (alpn_ctx.data) - OPENSSL_free(alpn_ctx.data); + OPENSSL_free(alpn_ctx.data); #endif ssl_excert_free(exc); sk_OPENSSL_STRING_free(ssl_args); diff --git a/apps/sess_id.c b/apps/sess_id.c index cfecd86a50..681654335a 100644 --- a/apps/sess_id.c +++ b/apps/sess_id.c @@ -211,8 +211,7 @@ int sess_id_main(int argc, char **argv) ret = 0; end: BIO_free_all(out); - if (x != NULL) - SSL_SESSION_free(x); + SSL_SESSION_free(x); return (ret); } diff --git a/apps/smime.c b/apps/smime.c index 8b8520b37c..e544ca2161 100644 --- a/apps/smime.c +++ b/apps/smime.c @@ -651,10 +651,8 @@ int smime_main(int argc, char **argv) sk_X509_pop_free(encerts, X509_free); sk_X509_pop_free(other, X509_free); X509_VERIFY_PARAM_free(vpm); - if (sksigners) - sk_OPENSSL_STRING_free(sksigners); - if (skkeys) - sk_OPENSSL_STRING_free(skkeys); + sk_OPENSSL_STRING_free(sksigners); + sk_OPENSSL_STRING_free(skkeys); X509_STORE_free(store); X509_free(cert); X509_free(recip); diff --git a/apps/srp.c b/apps/srp.c index 960ca822f7..8b44780c93 100644 --- a/apps/srp.c +++ b/apps/srp.c @@ -669,11 +669,8 @@ int srp_main(int argc, char **argv) ERR_print_errors(bio_err); if (randfile) app_RAND_write_file(randfile); - if (conf) - NCONF_free(conf); - if (db) - free_index(db); - + NCONF_free(conf); + free_index(db); OBJ_cleanup(); return (ret); } diff --git a/apps/x509.c b/apps/x509.c index 31ae38aeaa..fe9b10994e 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -949,8 +949,7 @@ int x509_main(int argc, char **argv) EVP_PKEY_free(Upkey); EVP_PKEY_free(CApkey); EVP_PKEY_free(fkey); - 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); |