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>
master
Rich Salz 2015-05-01 14:37:16 -04:00
parent 666964780a
commit 25aaa98aa2
82 changed files with 244 additions and 511 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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? */

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -97,8 +97,7 @@ void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x)
p = (unsigned char *)b->data;
ret = d2i(x, &p, len);
err:
if (b != NULL)
BUF_MEM_free(b);
BUF_MEM_free(b);
return (ret);
}
@ -118,8 +117,7 @@ void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
p = (const unsigned char *)b->data;
ret = ASN1_item_d2i(x, &p, len, it);
err:
if (b != NULL)
BUF_MEM_free(b);
BUF_MEM_free(b);
return (ret);
}
@ -264,7 +262,6 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
*pb = b;
return off;
err:
if (b != NULL)
BUF_MEM_free(b);
BUF_MEM_free(b);
return -1;
}

View File

@ -116,8 +116,7 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
return 1;
err:
if (pbe != NULL)
PBEPARAM_free(pbe);
PBEPARAM_free(pbe);
ASN1_STRING_free(pbe_str);
return 0;
}

View File

@ -281,10 +281,8 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
if (!crl->meth->crl_free(crl))
return 0;
}
if (crl->akid)
AUTHORITY_KEYID_free(crl->akid);
if (crl->idp)
ISSUING_DIST_POINT_free(crl->idp);
AUTHORITY_KEYID_free(crl->akid);
ISSUING_DIST_POINT_free(crl->idp);
ASN1_INTEGER_free(crl->crl_number);
ASN1_INTEGER_free(crl->base_crl_number);
sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);

View File

@ -105,10 +105,7 @@ CMS_ContentInfo *cms_CompressedData_create(int comp_nid)
return cms;
err:
if (cms)
CMS_ContentInfo_free(cms);
CMS_ContentInfo_free(cms);
return NULL;
}

View File

@ -88,10 +88,7 @@ CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md)
return cms;
err:
if (cms)
CMS_ContentInfo_free(cms);
CMS_ContentInfo_free(cms);
return NULL;
}

View File

@ -194,7 +194,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
ok = 1;
err:
if (ec->key && !keep_key) {
if (!keep_key) {
OPENSSL_clear_free(ec->key, ec->keylen);
ec->key = NULL;
}

View File

@ -168,8 +168,7 @@ CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher)
goto merr;
return cms;
merr:
if (cms)
CMS_ContentInfo_free(cms);
CMS_ContentInfo_free(cms);
CMSerr(CMS_F_CMS_ENVELOPEDDATA_CREATE, ERR_R_MALLOC_FAILURE);
return NULL;
}
@ -400,10 +399,8 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
ret = 1;
err:
if (pctx) {
EVP_PKEY_CTX_free(pctx);
ktri->pctx = NULL;
}
EVP_PKEY_CTX_free(pctx);
ktri->pctx = NULL;
OPENSSL_free(ek);
return ret;

View File

@ -128,9 +128,7 @@ CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen,
CMSerr(CMS_F_CMS_RECEIPTREQUEST_CREATE0, ERR_R_MALLOC_FAILURE);
err:
if (rr)
CMS_ReceiptRequest_free(rr);
CMS_ReceiptRequest_free(rr);
return NULL;
}
@ -337,10 +335,8 @@ int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms)
r = 1;
err:
if (rr)
CMS_ReceiptRequest_free(rr);
CMS_ReceiptRequest_free(rr);
M_ASN1_free_of(rct, CMS_Receipt);
return r;
}
@ -384,9 +380,6 @@ ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si)
os = ASN1_item_pack(&rct, ASN1_ITEM_rptr(CMS_Receipt), NULL);
err:
if (rr)
CMS_ReceiptRequest_free(rr);
CMS_ReceiptRequest_free(rr);
return os;
}

View File

@ -207,10 +207,9 @@ int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk)
{
EVP_PKEY_CTX *pctx;
CMS_KeyAgreeRecipientInfo *kari = ri->d.kari;
if (kari->pctx) {
EVP_PKEY_CTX_free(kari->pctx);
kari->pctx = NULL;
}
EVP_PKEY_CTX_free(kari->pctx);
kari->pctx = NULL;
if (!pk)
return 1;
pctx = EVP_PKEY_CTX_new(pk, NULL);

View File

@ -512,8 +512,7 @@ CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey,
CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE);
err:
if (cms)
CMS_ContentInfo_free(cms);
CMS_ContentInfo_free(cms);
return NULL;
}
@ -614,8 +613,7 @@ CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,
merr:
CMSerr(CMS_F_CMS_ENCRYPT, ERR_R_MALLOC_FAILURE);
err:
if (cms)
CMS_ContentInfo_free(cms);
CMS_ContentInfo_free(cms);
return NULL;
}

View File

@ -391,19 +391,17 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
v = NULL;
}
}
if (buff != NULL)
BUF_MEM_free(buff);
BUF_MEM_free(buff);
OPENSSL_free(section);
return (1);
err:
if (buff != NULL)
BUF_MEM_free(buff);
BUF_MEM_free(buff);
OPENSSL_free(section);
if (line != NULL)
*line = eline;
BIO_snprintf(btmp, sizeof btmp, "%ld", eline);
ERR_add_error_data(2, "line ", btmp);
if ((h != conf->data) && (conf->data != NULL)) {
if (h != conf->data) {
CONF_free(conf->data);
conf->data = NULL;
}
@ -595,8 +593,7 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
OPENSSL_free(buf);
return (1);
err:
if (buf != NULL)
BUF_MEM_free(buf);
BUF_MEM_free(buf);
return (0);
}

View File

@ -994,7 +994,6 @@ int i2d_ECPKParameters(const EC_GROUP *a, unsigned char **out)
EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
{
int ok = 0;
EC_KEY *ret = NULL;
EC_PRIVATEKEY *priv_key = NULL;
@ -1075,18 +1074,14 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
if (a)
*a = ret;
ok = 1;
err:
if (!ok) {
if (a == NULL || *a != ret)
EC_KEY_free(ret);
ret = NULL;
}
if (priv_key)
EC_PRIVATEKEY_free(priv_key);
EC_PRIVATEKEY_free(priv_key);
return (ret);
err:
if (a == NULL || *a != ret)
EC_KEY_free(ret);
EC_PRIVATEKEY_free(priv_key);
return NULL;
}
int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
@ -1190,8 +1185,7 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
ok = 1;
err:
OPENSSL_free(buffer);
if (priv_key)
EC_PRIVATEKEY_free(priv_key);
EC_PRIVATEKEY_free(priv_key);
return (ok ? ret : 0);
}

View File

@ -132,16 +132,11 @@ void EC_GROUP_free(EC_GROUP *group)
group->meth->group_finish(group);
EC_EX_DATA_free_all_data(&group->extra_data);
BN_MONT_CTX_free(group->mont_data);
EC_POINT_free(group->generator);
BN_free(group->order);
BN_free(group->cofactor);
if (group->seed)
OPENSSL_free(group->seed);
OPENSSL_free(group->seed);
OPENSSL_free(group);
}

View File

@ -742,8 +742,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
if (ctx != NULL)
BN_CTX_end(ctx);
BN_CTX_free(new_ctx);
if (pre_comp)
ec_pre_comp_free(pre_comp);
ec_pre_comp_free(pre_comp);
if (points) {
EC_POINT **p;

View File

@ -189,8 +189,7 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
DSO_free(ctx->dynamic_dso);
OPENSSL_free(ctx->DYNAMIC_LIBNAME);
OPENSSL_free(ctx->engine_id);
if (ctx->dirs)
sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str);
sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str);
OPENSSL_free(ctx);
}
}

View File

@ -559,10 +559,8 @@ void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
void ERR_free_strings(void)
{
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
if (int_error_hash) {
lh_ERR_STRING_DATA_free(int_error_hash);
int_error_hash = NULL;
}
lh_ERR_STRING_DATA_free(int_error_hash);
int_error_hash = NULL;
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
}

View File

@ -524,10 +524,8 @@ static void int_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
}
}
OPENSSL_free(storage);
if (ad->sk) {
sk_void_free(ad->sk);
ad->sk = NULL;
}
sk_void_free(ad->sk);
ad->sk = NULL;
}
/********************************************************************/

View File

@ -197,10 +197,10 @@ static CRYPTO_THREADID disabling_threadid;
static void app_info_free(APP_INFO *inf)
{
if (!inf)
return;
if (--(inf->references) <= 0) {
if (inf->next != NULL) {
app_info_free(inf->next);
}
app_info_free(inf->next);
OPENSSL_free(inf);
}
}
@ -559,8 +559,7 @@ void CRYPTO_dbg_free(void *addr, int before_p)
fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] - 0x%p (%d)\n",
mp->order, mp->addr, mp->num);
#endif
if (mp->app_info != NULL)
app_info_free(mp->app_info);
app_info_free(mp->app_info);
OPENSSL_free(mp);
}
@ -763,10 +762,8 @@ void CRYPTO_mem_leaks(BIO *b)
old_mh_mode = mh_mode;
mh_mode = CRYPTO_MEM_CHECK_OFF;
if (mh != NULL) {
lh_MEM_free(mh);
mh = NULL;
}
lh_MEM_free(mh);
mh = NULL;
if (amih != NULL) {
if (lh_APP_INFO_num_items(amih) == 0) {
lh_APP_INFO_free(amih);

View File

@ -91,8 +91,7 @@ OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid)
if (!(one = OCSP_ONEREQ_new()))
goto err;
if (one->reqCert)
OCSP_CERTID_free(one->reqCert);
OCSP_CERTID_free(one->reqCert);
one->reqCert = cid;
if (req && !sk_OCSP_ONEREQ_push(req->tbsRequest->requestList, one))
goto err;
@ -107,6 +106,7 @@ OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid)
int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
{
GENERAL_NAME *gen;
gen = GENERAL_NAME_new();
if (gen == NULL)
return 0;
@ -115,8 +115,7 @@ int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
return 0;
}
gen->type = GEN_DIRNAME;
if (req->tbsRequest->requestorName)
GENERAL_NAME_free(req->tbsRequest->requestorName);
GENERAL_NAME_free(req->tbsRequest->requestorName);
req->tbsRequest->requestorName = gen;
return 1;
}

View File

@ -437,8 +437,7 @@ X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim)
}
x = X509V3_EXT_i2d(NID_id_pkix_OCSP_CrlID, 0, cid);
err:
if (cid)
OCSP_CRLID_free(cid);
OCSP_CRLID_free(cid);
return x;
}
@ -516,7 +515,6 @@ X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, char **urls)
}
x = X509V3_EXT_i2d(NID_id_pkix_OCSP_serviceLocator, 0, sloc);
err:
if (sloc)
OCSP_SERVICELOC_free(sloc);
OCSP_SERVICELOC_free(sloc);
return x;
}

View File

@ -142,8 +142,7 @@ OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
digerr:
OCSPerr(OCSP_F_OCSP_CERT_ID_NEW, OCSP_R_DIGEST_ERR);
err:
if (cid)
OCSP_CERTID_free(cid);
OCSP_CERTID_free(cid);
return NULL;
}

View File

@ -130,8 +130,7 @@ OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs)
goto err;
return rsp;
err:
if (rsp)
OCSP_RESPONSE_free(rsp);
OCSP_RESPONSE_free(rsp);
return NULL;
}

View File

@ -674,6 +674,7 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
const unsigned char *p = *in;
unsigned int magic;
unsigned char *enctmp = NULL, *q;
EVP_CIPHER_CTX cctx;
EVP_CIPHER_CTX_init(&cctx);
if (saltlen) {
@ -736,8 +737,7 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
ret = b2i_PrivateKey(&p, keylen);
err:
EVP_CIPHER_CTX_cleanup(&cctx);
if (saltlen)
OPENSSL_free(enctmp);
OPENSSL_free(enctmp);
return ret;
}

View File

@ -82,9 +82,6 @@ pitem *pitem_new(unsigned char *prio64be, void *data)
void pitem_free(pitem *item)
{
if (item == NULL)
return;
OPENSSL_free(item);
}
@ -100,9 +97,6 @@ pqueue_s *pqueue_new()
void pqueue_free(pqueue_s *pq)
{
if (pq == NULL)
return;
OPENSSL_free(pq);
}

View File

@ -378,8 +378,7 @@ static int rsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,
X509_ALGOR *maskHash;
pss = rsa_pss_decode(sigalg, &maskHash);
rv = rsa_pss_param_print(bp, pss, maskHash, indent);
if (pss)
RSA_PSS_PARAMS_free(pss);
RSA_PSS_PARAMS_free(pss);
X509_ALGOR_free(maskHash);
if (!rv)
return 0;
@ -557,8 +556,7 @@ static ASN1_STRING *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx)
goto err;
rv = 1;
err:
if (pss)
RSA_PSS_PARAMS_free(pss);
RSA_PSS_PARAMS_free(pss);
if (rv)
return os;
ASN1_STRING_free(os);
@ -896,8 +894,7 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri)
os = NULL;
rv = 1;
err:
if (oaep)
RSA_OAEP_PARAMS_free(oaep);
RSA_OAEP_PARAMS_free(oaep);
ASN1_STRING_free(os);
return rv;
}

View File

@ -106,8 +106,7 @@ _STACK *sk_dup(_STACK *sk)
ret->comp = sk->comp;
return (ret);
err:
if (ret)
sk_free(ret);
sk_free(ret);
return (NULL);
}

View File

@ -346,7 +346,7 @@ static int mem_list_end(STORE *s, void *handle)
STOREerr(STORE_F_MEM_LIST_END, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if (context && context->search_attributes)
if (context)
sk_STORE_ATTR_INFO_free(context->search_attributes);
OPENSSL_free(context);
return 1;

View File

@ -718,8 +718,7 @@ static int TS_check_signer_name(GENERAL_NAME *tsa_name, X509 *signer)
gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name,
NULL, &idx);
}
if (gen_names)
GENERAL_NAMES_free(gen_names);
GENERAL_NAMES_free(gen_names);
return found;
}

View File

@ -71,7 +71,6 @@ const char TXT_DB_version[] = "TXT_DB" OPENSSL_VERSION_PTEXT;
TXT_DB *TXT_DB_read(BIO *in, int num)
{
TXT_DB *ret = NULL;
int er = 1;
int esc = 0;
long ln = 0;
int i, add, n;
@ -161,36 +160,23 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",
ln, num, n, f);
#endif
er = 2;
goto err;
}
pp[n] = p;
if (!sk_OPENSSL_PSTRING_push(ret->data, pp)) {
#if !defined(OPENSSL_NO_STDIO) /* temporary fix :-( */
fprintf(stderr, "failure in sk_push\n");
#endif
er = 2;
if (!sk_OPENSSL_PSTRING_push(ret->data, pp))
goto err;
}
}
er = 0;
BUF_MEM_free(buf);
return ret;
err:
BUF_MEM_free(buf);
if (er) {
#if !defined(OPENSSL_NO_STDIO)
if (er == 1)
fprintf(stderr, "OPENSSL_malloc failure\n");
#endif
if (ret != NULL) {
if (ret->data != NULL)
sk_OPENSSL_PSTRING_free(ret->data);
OPENSSL_free(ret->index);
OPENSSL_free(ret->qual);
OPENSSL_free(ret);
}
return (NULL);
} else
return (ret);
if (ret != NULL) {
sk_OPENSSL_PSTRING_free(ret->data);
OPENSSL_free(ret->index);
OPENSSL_free(ret->qual);
OPENSSL_free(ret);
}
return (NULL);
}
OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx,
@ -242,8 +228,7 @@ int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *),
return (0);
}
}
if (db->index[field] != NULL)
lh_OPENSSL_STRING_free(db->index[field]);
lh_OPENSSL_STRING_free(db->index[field]);
db->index[field] = idx;
db->qual[field] = qual;
return (1);
@ -292,8 +277,7 @@ long TXT_DB_write(BIO *out, TXT_DB *db)
}
ret = tot;
err:
if (buf != NULL)
BUF_MEM_free(buf);
BUF_MEM_free(buf);
return (ret);
}
@ -343,8 +327,7 @@ void TXT_DB_free(TXT_DB *db)
if (db->index != NULL) {
for (i = db->num_fields - 1; i >= 0; i--)
if (db->index[i] != NULL)
lh_OPENSSL_STRING_free(db->index[i]);
lh_OPENSSL_STRING_free(db->index[i]);
OPENSSL_free(db->index);
}
OPENSSL_free(db->qual);

View File

@ -177,8 +177,7 @@ static int by_dir_hash_cmp(const BY_DIR_HASH *const *a,
static void by_dir_entry_free(BY_DIR_ENTRY *ent)
{
OPENSSL_free(ent->dir);
if (ent->hashes)
sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);
sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);
OPENSSL_free(ent);
}
@ -187,10 +186,8 @@ static void free_dir(X509_LOOKUP *lu)
BY_DIR *a;
a = (BY_DIR *)lu->method_data;
if (a->dirs != NULL)
sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free);
if (a->buffer != NULL)
BUF_MEM_free(a->buffer);
sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free);
BUF_MEM_free(a->buffer);
OPENSSL_free(a);
}
@ -435,7 +432,6 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
}
}
finish:
if (b != NULL)
BUF_MEM_free(b);
BUF_MEM_free(b);
return (ok);
}

View File

@ -207,7 +207,6 @@ char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
return (p);
err:
X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
if (b != NULL)
BUF_MEM_free(b);
BUF_MEM_free(b);
return (NULL);
}