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>
This commit is contained in:
18
apps/apps.c
18
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
23
apps/ca.c
23
apps/ca.c
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
27
apps/cms.c
27
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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? */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user