I think this can be extended to expressions, not just identifiers:
@@
expression x;
@@
-if (x) { free(x); }
+free(x);
This catches another 47 instances. A patch against CVS follows.
diff -u -p a/src/apps/s_server.c b/src/apps/s_server.c
--- a/src/apps/s_server.c
+++ b/src/apps/s_server.c
@@ -1461,12 +1461,9 @@ end:
if (vpm)
X509_VERIFY_PARAM_free(vpm);
#ifndef OPENSSL_NO_TLSEXT
- if (tlscstatp.host)
- free(tlscstatp.host);
- if (tlscstatp.port)
- free(tlscstatp.port);
- if (tlscstatp.path)
- free(tlscstatp.path);
+ free(tlscstatp.host);
+ free(tlscstatp.port);
+ free(tlscstatp.path);
if (ctx2 != NULL)
SSL_CTX_free(ctx2);
if (s_cert2)
diff -u -p a/src/crypto/asn1/tasn_utl.c b/src/crypto/asn1/tasn_utl.c
--- a/src/crypto/asn1/tasn_utl.c
+++ b/src/crypto/asn1/tasn_utl.c
@@ -153,8 +153,7 @@ asn1_enc_free(ASN1_VALUE **pval, const A
enc = asn1_get_enc_ptr(pval, it);
if (enc) {
- if (enc->enc)
- free(enc->enc);
+ free(enc->enc);
enc->enc = NULL;
enc->len = 0;
enc->modified = 1;
@@ -171,8 +170,7 @@ asn1_enc_save(ASN1_VALUE **pval, const u
if (!enc)
return 1;
- if (enc->enc)
- free(enc->enc);
+ free(enc->enc);
enc->enc = malloc(inlen);
if (!enc->enc)
return 0;
diff -u -p a/src/crypto/asn1/ameth_lib.c b/src/crypto/asn1/ameth_lib.c
--- a/src/crypto/asn1/ameth_lib.c
+++ b/src/crypto/asn1/ameth_lib.c
@@ -380,10 +380,8 @@ void
EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
{
if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
- if (ameth->pem_str)
- free(ameth->pem_str);
- if (ameth->info)
- free(ameth->info);
+ free(ameth->pem_str);
+ free(ameth->info);
free(ameth);
}
}
diff -u -p a/src/crypto/asn1/asn1_lib.c b/src/crypto/asn1/asn1_lib.c
--- a/src/crypto/asn1/asn1_lib.c
+++ b/src/crypto/asn1/asn1_lib.c
@@ -401,8 +401,7 @@ ASN1_STRING_set(ASN1_STRING *str, const
void
ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
{
- if (str->data)
- free(str->data);
+ free(str->data);
str->data = data;
str->length = len;
}
diff -u -p a/src/crypto/asn1/asn_mime.c b/src/crypto/asn1/asn_mime.c
--- a/src/crypto/asn1/asn_mime.c
+++ b/src/crypto/asn1/asn_mime.c
@@ -949,10 +949,8 @@ mime_param_find(MIME_HEADER *hdr, char *
static void
mime_hdr_free(MIME_HEADER *hdr)
{
- if (hdr->name)
- free(hdr->name);
- if (hdr->value)
- free(hdr->value);
+ free(hdr->name);
+ free(hdr->value);
if (hdr->params)
sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
free(hdr);
@@ -961,10 +959,8 @@ mime_hdr_free(MIME_HEADER *hdr)
static void
mime_param_free(MIME_PARAM *param)
{
- if (param->param_name)
- free(param->param_name);
- if (param->param_value)
- free(param->param_value);
+ free(param->param_name);
+ free(param->param_value);
free(param);
}
diff -u -p a/src/crypto/asn1/bio_asn1.c b/src/crypto/asn1/bio_asn1.c
--- a/src/crypto/asn1/bio_asn1.c
+++ b/src/crypto/asn1/bio_asn1.c
@@ -186,8 +186,7 @@ asn1_bio_free(BIO *b)
ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
if (ctx == NULL)
return 0;
- if (ctx->buf)
- free(ctx->buf);
+ free(ctx->buf);
free(ctx);
b->init = 0;
b->ptr = NULL;
diff -u -p a/src/crypto/asn1/bio_ndef.c b/src/crypto/asn1/bio_ndef.c
--- a/src/crypto/asn1/bio_ndef.c
+++ b/src/crypto/asn1/bio_ndef.c
@@ -186,8 +186,7 @@ ndef_prefix_free(BIO *b, unsigned char *
ndef_aux = *(NDEF_SUPPORT **)parg;
- if (ndef_aux->derbuf)
- free(ndef_aux->derbuf);
+ free(ndef_aux->derbuf);
ndef_aux->derbuf = NULL;
*pbuf = NULL;
diff -u -p a/src/crypto/asn1/tasn_dec.c b/src/crypto/asn1/tasn_dec.c
--- a/src/crypto/asn1/tasn_dec.c
+++ b/src/crypto/asn1/tasn_dec.c
@@ -951,8 +951,7 @@ asn1_ex_c2i(ASN1_VALUE **pval, const uns
}
/* If we've already allocated a buffer use it */
if (*free_cont) {
- if (stmp->data)
- free(stmp->data);
+ free(stmp->data);
stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
stmp->length = len;
*free_cont = 0;
diff -u -p a/src/crypto/asn1/x_name.c b/src/crypto/asn1/x_name.c
--- a/src/crypto/asn1/x_name.c
+++ b/src/crypto/asn1/x_name.c
@@ -164,8 +164,7 @@ x509_name_ex_free(ASN1_VALUE **pval, con
BUF_MEM_free(a->bytes);
sk_X509_NAME_ENTRY_pop_free(a->entries, X509_NAME_ENTRY_free);
- if (a->canon_enc)
- free(a->canon_enc);
+ free(a->canon_enc);
free(a);
*pval = NULL;
}
diff -u -p a/src/crypto/asn1/x_pubkey.c b/src/crypto/asn1/x_pubkey.c
--- a/src/crypto/asn1/x_pubkey.c
+++ b/src/crypto/asn1/x_pubkey.c
@@ -355,8 +355,7 @@ X509_PUBKEY_set0_param(X509_PUBKEY *pub,
if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
return 0;
if (penc) {
- if (pub->public_key->data)
- free(pub->public_key->data);
+ free(pub->public_key->data);
pub->public_key->data = penc;
pub->public_key->length = penclen;
/* Set number of unused bits to zero */
diff -u -p a/src/crypto/conf/conf_mod.c b/src/crypto/conf/conf_mod.c
--- a/src/crypto/conf/conf_mod.c
+++ b/src/crypto/conf/conf_mod.c
@@ -386,10 +386,8 @@ err:
memerr:
if (imod) {
- if (imod->name)
- free(imod->name);
- if (imod->value)
- free(imod->value);
+ free(imod->name);
+ free(imod->value);
free(imod);
}
diff -u -p a/src/crypto/dh/dh_lib.c b/src/crypto/dh/dh_lib.c
--- a/src/crypto/dh/dh_lib.c
+++ b/src/crypto/dh/dh_lib.c
@@ -193,7 +193,7 @@ void DH_free(DH *r)
if (r->g != NULL) BN_clear_free(r->g);
if (r->q != NULL) BN_clear_free(r->q);
if (r->j != NULL) BN_clear_free(r->j);
- if (r->seed) free(r->seed);
+ free(r->seed);
if (r->counter != NULL) BN_clear_free(r->counter);
if (r->pub_key != NULL) BN_clear_free(r->pub_key);
if (r->priv_key != NULL) BN_clear_free(r->priv_key);
diff -u -p a/src/crypto/dso/dso_lib.c b/src/crypto/dso/dso_lib.c
--- a/src/crypto/dso/dso_lib.c
+++ b/src/crypto/dso/dso_lib.c
@@ -361,8 +361,7 @@ DSO_set_filename(DSO *dso, const char *f
DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE);
return (0);
}
- if (dso->filename)
- free(dso->filename);
+ free(dso->filename);
dso->filename = copied;
return (1);
}
diff -u -p a/src/crypto/ec/ec_lib.c b/src/crypto/ec/ec_lib.c
--- a/src/crypto/ec/ec_lib.c
+++ b/src/crypto/ec/ec_lib.c
@@ -130,8 +130,7 @@ EC_GROUP_free(EC_GROUP * group)
BN_free(&group->order);
BN_free(&group->cofactor);
- if (group->seed)
- free(group->seed);
+ free(group->seed);
free(group);
}
@@ -218,8 +217,7 @@ EC_GROUP_copy(EC_GROUP * dest, const EC_
dest->asn1_form = src->asn1_form;
if (src->seed) {
- if (dest->seed)
- free(dest->seed);
+ free(dest->seed);
dest->seed = malloc(src->seed_len);
if (dest->seed == NULL)
return 0;
@@ -227,8 +225,7 @@ EC_GROUP_copy(EC_GROUP * dest, const EC_
return 0;
dest->seed_len = src->seed_len;
} else {
- if (dest->seed)
- free(dest->seed);
+ free(dest->seed);
dest->seed = NULL;
dest->seed_len = 0;
}
diff -u -p a/src/crypto/engine/hw_cryptodev.c b/src/crypto/engine/hw_cryptodev.c
--- a/src/crypto/engine/hw_cryptodev.c
+++ b/src/crypto/engine/hw_cryptodev.c
@@ -926,8 +926,7 @@ zapparams(struct crypt_kop *kop)
int i;
for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
- if (kop->crk_param[i].crp_p)
- free(kop->crk_param[i].crp_p);
+ free(kop->crk_param[i].crp_p);
kop->crk_param[i].crp_p = NULL;
kop->crk_param[i].crp_nbits = 0;
}
diff -u -p a/src/crypto/evp/evp_enc.c b/src/crypto/evp/evp_enc.c
--- a/src/crypto/evp/evp_enc.c
+++ b/src/crypto/evp/evp_enc.c
@@ -548,8 +548,7 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c
if (c->cipher_data)
OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
}
- if (c->cipher_data)
- free(c->cipher_data);
+ free(c->cipher_data);
#ifndef OPENSSL_NO_ENGINE
if (c->engine)
/* The EVP_CIPHER we used belongs to an ENGINE, release the
diff -u -p a/src/crypto/ocsp/ocsp_ht.c b/src/crypto/ocsp/ocsp_ht.c
--- a/src/crypto/ocsp/ocsp_ht.c
+++ b/src/crypto/ocsp/ocsp_ht.c
@@ -110,8 +110,7 @@ OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx)
{
if (rctx->mem)
BIO_free(rctx->mem);
- if (rctx->iobuf)
- free(rctx->iobuf);
+ free(rctx->iobuf);
free(rctx);
}
diff -u -p a/src/crypto/rsa/rsa_pmeth.c b/src/crypto/rsa/rsa_pmeth.c
--- a/src/crypto/rsa/rsa_pmeth.c
+++ b/src/crypto/rsa/rsa_pmeth.c
@@ -148,8 +148,7 @@ static void pkey_rsa_cleanup(EVP_PKEY_CT
{
if (rctx->pub_exp)
BN_free(rctx->pub_exp);
- if (rctx->tbuf)
- free(rctx->tbuf);
+ free(rctx->tbuf);
free(rctx);
}
}
diff -u -p a/src/crypto/x509/by_dir.c b/src/crypto/x509/by_dir.c
--- a/src/crypto/x509/by_dir.c
+++ b/src/crypto/x509/by_dir.c
@@ -184,8 +184,7 @@ by_dir_hash_cmp(const BY_DIR_HASH * cons
static void
by_dir_entry_free(BY_DIR_ENTRY *ent)
{
- if (ent->dir)
- free(ent->dir);
+ free(ent->dir);
if (ent->hashes)
sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);
free(ent);
diff -u -p a/src/crypto/x509/x509_vpm.c b/src/crypto/x509/x509_vpm.c
--- a/src/crypto/x509/x509_vpm.c
+++ b/src/crypto/x509/x509_vpm.c
@@ -213,8 +213,7 @@ X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM
int
X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name)
{
- if (param->name)
- free(param->name);
+ free(param->name);
param->name = BUF_strdup(name);
if (param->name)
return 1;
diff -u -p a/src/crypto/x509v3/v3_utl.c b/src/crypto/x509v3/v3_utl.c
--- a/src/crypto/x509v3/v3_utl.c
+++ b/src/crypto/x509v3/v3_utl.c
@@ -111,9 +111,9 @@ int X509V3_add_value_uchar(const char *n
void X509V3_conf_free(CONF_VALUE *conf)
{
if(!conf) return;
- if(conf->name) free(conf->name);
- if(conf->value) free(conf->value);
- if(conf->section) free(conf->section);
+ free(conf->name);
+ free(conf->value);
+ free(conf->section);
free(conf);
}
diff -u -p a/src/ssl/d1_both.c b/src/ssl/d1_both.c
--- a/src/ssl/d1_both.c
+++ b/src/ssl/d1_both.c
@@ -223,10 +223,8 @@ dtls1_hm_fragment_free(hm_fragment *frag
EVP_MD_CTX_destroy(
frag->msg_header.saved_retransmit_state.write_hash);
}
- if (frag->fragment)
- free(frag->fragment);
- if (frag->reassembly)
- free(frag->reassembly);
+ free(frag->fragment);
+ free(frag->reassembly);
free(frag);
}
diff -u -p a/src/ssl/d1_lib.c b/src/ssl/d1_lib.c
--- a/src/ssl/d1_lib.c
+++ b/src/ssl/d1_lib.c
@@ -147,18 +147,14 @@ dtls1_clear_queues(SSL *s)
while ((item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *) item->data;
- if (rdata->rbuf.buf) {
- free(rdata->rbuf.buf);
- }
+ free(rdata->rbuf.buf);
free(item->data);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->processed_rcds.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *) item->data;
- if (rdata->rbuf.buf) {
- free(rdata->rbuf.buf);
- }
+ free(rdata->rbuf.buf);
free(item->data);
pitem_free(item);
}
diff -u -p a/src/ssl/s3_clnt.c b/src/ssl/s3_clnt.c
--- a/src/ssl/s3_clnt.c
+++ b/src/ssl/s3_clnt.c
@@ -1257,8 +1257,7 @@ ssl3_get_key_exchange(SSL *s)
*/
if (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK) {
s->session->sess_cert = ssl_sess_cert_new();
- if (s->ctx->psk_identity_hint)
- free(s->ctx->psk_identity_hint);
+ free(s->ctx->psk_identity_hint);
s->ctx->psk_identity_hint = NULL;
}
#endif
@@ -1993,8 +1992,7 @@ ssl3_get_cert_status(SSL *s)
SSL_R_LENGTH_MISMATCH);
goto f_err;
}
- if (s->tlsext_ocsp_resp)
- free(s->tlsext_ocsp_resp);
+ free(s->tlsext_ocsp_resp);
s->tlsext_ocsp_resp = BUF_memdup(p, resplen);
if (!s->tlsext_ocsp_resp) {
al = SSL_AD_INTERNAL_ERROR;
diff -u -p a/src/ssl/ssl_lib.c b/src/ssl/ssl_lib.c
--- a/src/ssl/ssl_lib.c
+++ b/src/ssl/ssl_lib.c
@@ -546,25 +546,20 @@ SSL_free(SSL *s)
/* Free up if allocated */
#ifndef OPENSSL_NO_TLSEXT
- if (s->tlsext_hostname)
- free(s->tlsext_hostname);
+ free(s->tlsext_hostname);
if (s->initial_ctx)
SSL_CTX_free(s->initial_ctx);
#ifndef OPENSSL_NO_EC
- if (s->tlsext_ecpointformatlist)
- free(s->tlsext_ecpointformatlist);
- if (s->tlsext_ellipticcurvelist)
- free(s->tlsext_ellipticcurvelist);
+ free(s->tlsext_ecpointformatlist);
+ free(s->tlsext_ellipticcurvelist);
#endif /* OPENSSL_NO_EC */
- if (s->tlsext_opaque_prf_input)
- free(s->tlsext_opaque_prf_input);
+ free(s->tlsext_opaque_prf_input);
if (s->tlsext_ocsp_exts)
sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,
X509_EXTENSION_free);
if (s->tlsext_ocsp_ids)
sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);
- if (s->tlsext_ocsp_resp)
- free(s->tlsext_ocsp_resp);
+ free(s->tlsext_ocsp_resp);
#endif
if (s->client_CA != NULL)
@@ -578,8 +573,7 @@ SSL_free(SSL *s)
#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
- if (s->next_proto_negotiated)
- free(s->next_proto_negotiated);
+ free(s->next_proto_negotiated);
#endif
#ifndef OPENSSL_NO_SRTP
@@ -1961,8 +1955,7 @@ SSL_CTX_free(SSL_CTX *a)
#endif
#ifndef OPENSSL_NO_PSK
- if (a->psk_identity_hint)
- free(a->psk_identity_hint);
+ free(a->psk_identity_hint);
#endif
#ifndef OPENSSL_NO_ENGINE
if (a->client_cert_engine)
diff -u -p a/src/ssl/t1_lib.c b/src/ssl/t1_lib.c
--- a/src/ssl/t1_lib.c
+++ b/src/ssl/t1_lib.c
@@ -161,9 +161,7 @@ void
tls1_free(SSL *s)
{
#ifndef OPENSSL_NO_TLSEXT
- if (s->tlsext_session_ticket) {
- free(s->tlsext_session_ticket);
- }
+ free(s->tlsext_session_ticket);
#endif /* OPENSSL_NO_TLSEXT */
ssl3_free(s);
}