diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2014-05-19 12:13:31 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2014-05-19 12:13:31 +0000 |
commit | 3d8c3f277959dc36c3c530b096f05e9de747d1ab (patch) | |
tree | ccd60f1d9c83a20c0358a346e6940660fd909079 | |
parent | 35133cac3aa5ff7f63644abb60258f299c91517e (diff) |
It is perfectly valid to call free(NULL), so stop checking for non-NULL
before calling free - of some course parts of the code already did this.
29 files changed, 80 insertions, 128 deletions
diff --git a/lib/libssl/src/apps/apps.c b/lib/libssl/src/apps/apps.c index 7c152414e9a..75f9fae77ca 100644 --- a/lib/libssl/src/apps/apps.c +++ b/lib/libssl/src/apps/apps.c @@ -1932,18 +1932,16 @@ parse_name(char *subject, long chtype, int multirdn) free(ne_types); free(buf); free(mval); + return n; error: X509_NAME_free(n); - if (ne_values) - free(ne_values); - if (ne_types) - free(ne_types); - if (mval) - free(mval); - if (buf) - free(buf); + free(ne_values); + free(ne_types); + free(mval); + free(buf); + return NULL; } @@ -2131,6 +2129,7 @@ pkey_ctrl_string(EVP_PKEY_CTX * ctx, char *value) } rv = EVP_PKEY_CTX_ctrl_str(ctx, stmp, vtmp); free(stmp); + return rv; } diff --git a/lib/libssl/src/apps/ca.c b/lib/libssl/src/apps/ca.c index 10b5c0b3fe0..8217f36198a 100644 --- a/lib/libssl/src/apps/ca.c +++ b/lib/libssl/src/apps/ca.c @@ -530,10 +530,9 @@ bad: errorline, configfile); goto err; } - if (tofree) { - free(tofree); - tofree = NULL; - } + free(tofree); + tofree = NULL; + if (!load_config(bio_err, conf)) goto err; @@ -1347,8 +1346,8 @@ bad: ret = 0; err: - if (tofree) - free(tofree); + free(tofree); + BIO_free_all(Cout); BIO_free_all(Sout); BIO_free_all(out); @@ -1996,8 +1995,7 @@ again2: ok = 1; err: for (i = 0; i < DB_NUMBER; i++) - if (row[i] != NULL) - free(row[i]); + free(row[i]); if (CAname != NULL) X509_NAME_free(CAname); @@ -2287,10 +2285,9 @@ do_revoke(X509 * x509, CA_DB * db, int type, char *value) ok = 1; err: - for (i = 0; i < DB_NUMBER; i++) { - if (row[i] != NULL) - free(row[i]); - } + for (i = 0; i < DB_NUMBER; i++) + free(row[i]); + return (ok); } @@ -2360,10 +2357,9 @@ get_certificate_status(const char *serial, CA_DB * db) } err: - for (i = 0; i < DB_NUMBER; i++) { - if (row[i] != NULL) - free(row[i]); - } + for (i = 0; i < DB_NUMBER; i++) + free(row[i]); + return (ok); } @@ -2575,8 +2571,8 @@ make_revoked(X509_REVOKED * rev, const char *str) ret = 1; err: - if (tmp) - free(tmp); + free(tmp); + ASN1_OBJECT_free(hold); ASN1_GENERALIZEDTIME_free(comp_time); ASN1_ENUMERATED_free(rtmp); @@ -2719,8 +2715,8 @@ unpack_revinfo(ASN1_TIME ** prevtm, int *preason, ASN1_OBJECT ** phold, ret = 1; err: - if (tmp) - free(tmp); + free(tmp); + if (!phold) ASN1_OBJECT_free(hold); if (!pinvtm) diff --git a/lib/libssl/src/apps/cms.c b/lib/libssl/src/apps/cms.c index 01b4a2a2621..d85690cf4b6 100644 --- a/lib/libssl/src/apps/cms.c +++ b/lib/libssl/src/apps/cms.c @@ -973,12 +973,9 @@ end: sk_OPENSSL_STRING_free(sksigners); if (skkeys) sk_OPENSSL_STRING_free(skkeys); - if (secret_key) - free(secret_key); - if (secret_keyid) - free(secret_keyid); - if (pwri_tmp) - free(pwri_tmp); + free(secret_key); + free(secret_keyid); + free(pwri_tmp); if (econtent_type) ASN1_OBJECT_free(econtent_type); if (rr) @@ -998,8 +995,7 @@ end: BIO_free(in); BIO_free(indata); BIO_free_all(out); - if (passin) - free(passin); + free(passin); return (ret); } diff --git a/lib/libssl/src/apps/dgst.c b/lib/libssl/src/apps/dgst.c index c1832297b2e..1017a362f58 100644 --- a/lib/libssl/src/apps/dgst.c +++ b/lib/libssl/src/apps/dgst.c @@ -476,16 +476,14 @@ end: } if (in != NULL) BIO_free(in); - if (passin) - free(passin); + free(passin); BIO_free_all(out); EVP_PKEY_free(sigkey); if (sigopts) sk_OPENSSL_STRING_free(sigopts); if (macopts) sk_OPENSSL_STRING_free(macopts); - if (sigbuf) - free(sigbuf); + free(sigbuf); if (bmd != NULL) BIO_free(bmd); diff --git a/lib/libssl/src/apps/dsa.c b/lib/libssl/src/apps/dsa.c index 4026ba5d229..c35d15016a5 100644 --- a/lib/libssl/src/apps/dsa.c +++ b/lib/libssl/src/apps/dsa.c @@ -332,10 +332,8 @@ end: BIO_free_all(out); if (dsa != NULL) DSA_free(dsa); - if (passin) - free(passin); - if (passout) - free(passout); + free(passin); + free(passout); return (ret); } diff --git a/lib/libssl/src/apps/ec.c b/lib/libssl/src/apps/ec.c index 6bd71c333ae..452d73cfdbe 100644 --- a/lib/libssl/src/apps/ec.c +++ b/lib/libssl/src/apps/ec.c @@ -339,10 +339,8 @@ end: BIO_free_all(out); if (eckey) EC_KEY_free(eckey); - if (passin) - free(passin); - if (passout) - free(passout); + free(passin); + free(passout); return (ret); } diff --git a/lib/libssl/src/apps/ecparam.c b/lib/libssl/src/apps/ecparam.c index e6d3ae71daa..3e8b7237204 100644 --- a/lib/libssl/src/apps/ecparam.c +++ b/lib/libssl/src/apps/ecparam.c @@ -587,8 +587,7 @@ end: BN_free(ec_order); if (ec_cofactor) BN_free(ec_cofactor); - if (buffer) - free(buffer); + free(buffer); if (in != NULL) BIO_free(in); if (out != NULL) diff --git a/lib/libssl/src/apps/enc.c b/lib/libssl/src/apps/enc.c index b31d10357f1..394995f02b8 100644 --- a/lib/libssl/src/apps/enc.c +++ b/lib/libssl/src/apps/enc.c @@ -609,10 +609,8 @@ enc_main(int argc, char **argv) } end: ERR_print_errors(bio_err); - if (strbuf != NULL) - free(strbuf); - if (buff != NULL) - free(buff); + free(strbuf); + free(buff); if (in != NULL) BIO_free(in); if (out != NULL) @@ -625,8 +623,7 @@ end: if (bzl != NULL) BIO_free(bzl); #endif - if (pass) - free(pass); + free(pass); return (ret); } diff --git a/lib/libssl/src/apps/engine.c b/lib/libssl/src/apps/engine.c index 2cf7bd2412e..07d69263d0c 100644 --- a/lib/libssl/src/apps/engine.c +++ b/lib/libssl/src/apps/engine.c @@ -259,10 +259,9 @@ util_verbose(ENGINE * e, int verbose, BIO * bio_out, const char *indent) } free(name); name = NULL; - if (desc) { - free(desc); - desc = NULL; - } + free(desc); + desc = NULL; + /* Move to the next command */ num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE, num, NULL, NULL); @@ -273,10 +272,8 @@ util_verbose(ENGINE * e, int verbose, BIO * bio_out, const char *indent) err: if (cmds) sk_OPENSSL_STRING_pop_free(cmds, identity); - if (name) - free(name); - if (desc) - free(desc); + free(name); + free(desc); return ret; } diff --git a/lib/libssl/src/apps/gendsa.c b/lib/libssl/src/apps/gendsa.c index cada26b45c1..f4f3fb0a0bd 100644 --- a/lib/libssl/src/apps/gendsa.c +++ b/lib/libssl/src/apps/gendsa.c @@ -238,8 +238,7 @@ end: BIO_free_all(out); if (dsa != NULL) DSA_free(dsa); - if (passout) - free(passout); + free(passout); return (ret); } diff --git a/lib/libssl/src/apps/genpkey.c b/lib/libssl/src/apps/genpkey.c index 5797de40573..fcd02ca7b5d 100644 --- a/lib/libssl/src/apps/genpkey.c +++ b/lib/libssl/src/apps/genpkey.c @@ -262,8 +262,7 @@ end: if (out) BIO_free_all(out); BIO_free(in); - if (pass) - free(pass); + free(pass); return ret; } diff --git a/lib/libssl/src/apps/genrsa.c b/lib/libssl/src/apps/genrsa.c index 96a678cbb83..899a99fc444 100644 --- a/lib/libssl/src/apps/genrsa.c +++ b/lib/libssl/src/apps/genrsa.c @@ -274,8 +274,7 @@ err: RSA_free(rsa); if (out) BIO_free_all(out); - if (passout) - free(passout); + free(passout); if (ret != 0) ERR_print_errors(bio_err); diff --git a/lib/libssl/src/apps/openssl.c b/lib/libssl/src/apps/openssl.c index 47428033cd6..272df028788 100644 --- a/lib/libssl/src/apps/openssl.c +++ b/lib/libssl/src/apps/openssl.c @@ -371,8 +371,7 @@ end: } if (prog != NULL) lh_FUNCTION_free(prog); - if (arg.data != NULL) - free(arg.data); + free(arg.data); openssl_shutdown(); diff --git a/lib/libssl/src/apps/passwd.c b/lib/libssl/src/apps/passwd.c index e87aed38e73..e9d0949d743 100644 --- a/lib/libssl/src/apps/passwd.c +++ b/lib/libssl/src/apps/passwd.c @@ -245,10 +245,8 @@ passwd_main(int argc, char **argv) err: ERR_print_errors(bio_err); - if (salt_malloc) - free(salt_malloc); - if (passwd_malloc) - free(passwd_malloc); + free(salt_malloc); + free(passwd_malloc); if (in) BIO_free(in); if (out) diff --git a/lib/libssl/src/apps/pkcs12.c b/lib/libssl/src/apps/pkcs12.c index aca248a50ab..5b85f97568a 100644 --- a/lib/libssl/src/apps/pkcs12.c +++ b/lib/libssl/src/apps/pkcs12.c @@ -697,10 +697,8 @@ end: BIO_free_all(out); if (canames) sk_OPENSSL_STRING_free(canames); - if (passin) - free(passin); - if (passout) - free(passout); + free(passin); + free(passout); return (ret); } diff --git a/lib/libssl/src/apps/pkcs8.c b/lib/libssl/src/apps/pkcs8.c index 1f1a11e4552..4cedc40f758 100644 --- a/lib/libssl/src/apps/pkcs8.c +++ b/lib/libssl/src/apps/pkcs8.c @@ -363,10 +363,8 @@ end: EVP_PKEY_free(pkey); BIO_free_all(out); BIO_free(in); - if (passin) - free(passin); - if (passout) - free(passout); + free(passin); + free(passout); return ret; } diff --git a/lib/libssl/src/apps/pkey.c b/lib/libssl/src/apps/pkey.c index 101ba5b2399..4ec19b9a624 100644 --- a/lib/libssl/src/apps/pkey.c +++ b/lib/libssl/src/apps/pkey.c @@ -231,10 +231,8 @@ end: EVP_PKEY_free(pkey); BIO_free_all(out); BIO_free(in); - if (passin) - free(passin); - if (passout) - free(passout); + free(passin); + free(passout); return ret; } diff --git a/lib/libssl/src/apps/pkeyutl.c b/lib/libssl/src/apps/pkeyutl.c index 46392e6902e..4f1cfed0e8b 100644 --- a/lib/libssl/src/apps/pkeyutl.c +++ b/lib/libssl/src/apps/pkeyutl.c @@ -322,12 +322,10 @@ end: EVP_PKEY_CTX_free(ctx); BIO_free(in); BIO_free_all(out); - if (buf_in) - free(buf_in); - if (buf_out) - free(buf_out); - if (sig) - free(sig); + free(buf_in); + free(buf_out); + free(sig); + return ret; } diff --git a/lib/libssl/src/apps/req.c b/lib/libssl/src/apps/req.c index 21ddb3b9c3e..d306a17ec66 100644 --- a/lib/libssl/src/apps/req.c +++ b/lib/libssl/src/apps/req.c @@ -912,8 +912,7 @@ end: if (gen_eng) ENGINE_free(gen_eng); #endif - if (keyalgstr) - free(keyalgstr); + free(keyalgstr); X509_REQ_free(req); X509_free(x509ss); ASN1_INTEGER_free(serial); diff --git a/lib/libssl/src/apps/rsa.c b/lib/libssl/src/apps/rsa.c index 0b9c87dd998..f651f614d11 100644 --- a/lib/libssl/src/apps/rsa.c +++ b/lib/libssl/src/apps/rsa.c @@ -391,10 +391,8 @@ end: BIO_free_all(out); if (rsa != NULL) RSA_free(rsa); - if (passin) - free(passin); - if (passout) - free(passout); + free(passin); + free(passout); return (ret); } diff --git a/lib/libssl/src/apps/rsautl.c b/lib/libssl/src/apps/rsautl.c index 55c89b271bb..08d28a496bd 100644 --- a/lib/libssl/src/apps/rsautl.c +++ b/lib/libssl/src/apps/rsautl.c @@ -305,16 +305,15 @@ rsautl_main(int argc, char **argv) BIO_dump(out, (char *) rsa_out, rsa_outlen); else BIO_write(out, rsa_out, rsa_outlen); + end: RSA_free(rsa); BIO_free(in); BIO_free_all(out); - if (rsa_in) - free(rsa_in); - if (rsa_out) - free(rsa_out); - if (passin) - free(passin); + free(rsa_in); + free(rsa_out); + free(passin); + return ret; } diff --git a/lib/libssl/src/apps/s_client.c b/lib/libssl/src/apps/s_client.c index d29f14709a0..bf4a7e082b7 100644 --- a/lib/libssl/src/apps/s_client.c +++ b/lib/libssl/src/apps/s_client.c @@ -1411,8 +1411,7 @@ end: SSL_free(con); } #if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG) - if (next_proto.data) - free(next_proto.data); + free(next_proto.data); #endif if (ctx != NULL) SSL_CTX_free(ctx); @@ -1420,8 +1419,7 @@ end: X509_free(cert); if (key) EVP_PKEY_free(key); - if (pass) - free(pass); + free(pass); if (vpm) X509_VERIFY_PARAM_free(vpm); if (cbuf != NULL) { diff --git a/lib/libssl/src/apps/s_server.c b/lib/libssl/src/apps/s_server.c index 333e09f3cab..99ebee4aa67 100644 --- a/lib/libssl/src/apps/s_server.c +++ b/lib/libssl/src/apps/s_server.c @@ -1457,10 +1457,8 @@ end: EVP_PKEY_free(s_key); if (s_dkey) EVP_PKEY_free(s_dkey); - if (pass) - free(pass); - if (dpass) - free(dpass); + free(pass); + free(dpass); if (vpm) X509_VERIFY_PARAM_free(vpm); #ifndef OPENSSL_NO_TLSEXT diff --git a/lib/libssl/src/apps/s_socket.c b/lib/libssl/src/apps/s_socket.c index a9bbe97ddf5..3d88cdf5914 100644 --- a/lib/libssl/src/apps/s_socket.c +++ b/lib/libssl/src/apps/s_socket.c @@ -167,8 +167,7 @@ do_server(int port, int type, int *ret, } else sock = accept_socket; i = (*cb) (name, sock, context); - if (name != NULL) - free(name); + free(name); if (type == SOCK_STREAM) { shutdown(sock, SHUT_RDWR); close(sock); diff --git a/lib/libssl/src/apps/smime.c b/lib/libssl/src/apps/smime.c index 78d783de469..69d47ee18f2 100644 --- a/lib/libssl/src/apps/smime.c +++ b/lib/libssl/src/apps/smime.c @@ -670,8 +670,8 @@ end: BIO_free(in); BIO_free(indata); BIO_free_all(out); - if (passin) - free(passin); + free(passin); + return (ret); } diff --git a/lib/libssl/src/apps/speed.c b/lib/libssl/src/apps/speed.c index 6bcb943bffa..d25db09ada9 100644 --- a/lib/libssl/src/apps/speed.c +++ b/lib/libssl/src/apps/speed.c @@ -2013,10 +2013,8 @@ show_res: end: ERR_print_errors(bio_err); - if (buf != NULL) - free(buf); - if (buf2 != NULL) - free(buf2); + free(buf); + free(buf2); #ifndef OPENSSL_NO_RSA for (i = 0; i < RSA_NUM; i++) if (rsa_key[i] != NULL) diff --git a/lib/libssl/src/apps/spkac.c b/lib/libssl/src/apps/spkac.c index 2fa7eac6b2b..33791c6cc6b 100644 --- a/lib/libssl/src/apps/spkac.c +++ b/lib/libssl/src/apps/spkac.c @@ -280,8 +280,7 @@ end: BIO_free(in); BIO_free_all(out); EVP_PKEY_free(pkey); - if (passin) - free(passin); + free(passin); return (ret); } diff --git a/lib/libssl/src/apps/ts.c b/lib/libssl/src/apps/ts.c index 2bb343d13c9..2674de9a574 100644 --- a/lib/libssl/src/apps/ts.c +++ b/lib/libssl/src/apps/ts.c @@ -548,6 +548,7 @@ err: free(data); ASN1_OBJECT_free(policy_obj); ASN1_INTEGER_free(nonce_asn1); + return ts_req; } diff --git a/lib/libssl/src/apps/x509.c b/lib/libssl/src/apps/x509.c index a488623c418..e77fd4ddd31 100644 --- a/lib/libssl/src/apps/x509.c +++ b/lib/libssl/src/apps/x509.c @@ -939,8 +939,7 @@ end: ASN1_INTEGER_free(sno); sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free); sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free); - if (passin) - free(passin); + free(passin); return (ret); } @@ -983,9 +982,9 @@ x509_load_serial(char *CAfile, char *serialfile, int create) goto end; end: - if (buf) - free(buf); + free(buf); BN_free(serial); + return bs; } |