summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2015-05-01 10:15:18 -0400
committerRich Salz <rsalz@openssl.org>2015-05-01 10:15:18 -0400
commitefa7dd64443f246004751bdaa5671bf6836e07ff (patch)
treedf55d807a97d046ce17eb12adca78ea36a6038fa /crypto
parentb548a1f11c06ccdfa4f52a539912d22d77ee309e (diff)
free NULL cleanup 11
Don't check for NULL before calling free functions. This gets: ERR_STATE_free ENGINE_free DSO_free CMAC_CTX_free COMP_CTX_free CONF_free NCONF_free NCONF_free_data _CONF_free_data A sk_free use within OBJ_sigid_free TS_TST_INFO_free (rest of TS_ API was okay) Doc update for UI_free (all uses were fine) X509V3_conf_free X509V3_section_free X509V3_string_free Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/asn1/asn1_gen.c3
-rw-r--r--crypto/asn1/asn_mstbl.c3
-rw-r--r--crypto/cmac/cm_ameth.c3
-rw-r--r--crypto/cmac/cmac.c2
-rw-r--r--crypto/comp/c_zlib.c3
-rw-r--r--crypto/conf/conf_api.c18
-rw-r--r--crypto/conf/conf_mod.c8
-rw-r--r--crypto/dso/dso_lib.c6
-rw-r--r--crypto/engine/eng_cnf.c3
-rw-r--r--crypto/engine/eng_dyn.c3
-rw-r--r--crypto/engine/eng_lib.c8
-rw-r--r--crypto/engine/eng_table.c2
-rw-r--r--crypto/err/err.c6
-rw-r--r--crypto/objects/obj_xref.c12
-rw-r--r--crypto/ts/ts_asn1.c6
-rw-r--r--crypto/ts/ts_conf.c3
16 files changed, 35 insertions, 54 deletions
diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c
index 6756c67a47..549bc5ef36 100644
--- a/crypto/asn1/asn1_gen.c
+++ b/crypto/asn1/asn1_gen.c
@@ -511,8 +511,7 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
OPENSSL_free(der);
sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
- if (sect)
- X509V3_section_free(cnf, sect);
+ X509V3_section_free(cnf, sect);
return ret;
}
diff --git a/crypto/asn1/asn_mstbl.c b/crypto/asn1/asn_mstbl.c
index 889cbe49c8..94ffbd8ada 100644
--- a/crypto/asn1/asn_mstbl.c
+++ b/crypto/asn1/asn_mstbl.c
@@ -154,7 +154,6 @@ static int do_tcreate(char *value, char *name)
if (!rv)
ASN1err(ASN1_F_DO_TCREATE, ERR_R_MALLOC_FAILURE);
}
- if (lst)
- sk_CONF_VALUE_pop_free(lst, X509V3_conf_free);
+ sk_CONF_VALUE_pop_free(lst, X509V3_conf_free);
return rv;
}
diff --git a/crypto/cmac/cm_ameth.c b/crypto/cmac/cm_ameth.c
index 98634c99e9..07853a63d3 100644
--- a/crypto/cmac/cm_ameth.c
+++ b/crypto/cmac/cm_ameth.c
@@ -70,8 +70,7 @@ static int cmac_size(const EVP_PKEY *pkey)
static void cmac_key_free(EVP_PKEY *pkey)
{
CMAC_CTX *cmctx = (CMAC_CTX *)pkey->pkey.ptr;
- if (cmctx)
- CMAC_CTX_free(cmctx);
+ CMAC_CTX_free(cmctx);
}
const EVP_PKEY_ASN1_METHOD cmac_asn1_meth = {
diff --git a/crypto/cmac/cmac.c b/crypto/cmac/cmac.c
index 19018480f2..5e8fdc399b 100644
--- a/crypto/cmac/cmac.c
+++ b/crypto/cmac/cmac.c
@@ -115,6 +115,8 @@ EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx)
void CMAC_CTX_free(CMAC_CTX *ctx)
{
+ if (!ctx)
+ return;
CMAC_CTX_cleanup(ctx);
OPENSSL_free(ctx);
}
diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c
index 4508e7f634..334c78f296 100644
--- a/crypto/comp/c_zlib.c
+++ b/crypto/comp/c_zlib.c
@@ -289,8 +289,7 @@ COMP_METHOD *COMP_zlib(void)
void COMP_zlib_cleanup(void)
{
#ifdef ZLIB_SHARED
- if (zlib_dso)
- DSO_free(zlib_dso);
+ DSO_free(zlib_dso);
#endif
}
diff --git a/crypto/conf/conf_api.c b/crypto/conf/conf_api.c
index b41564b680..59808a301b 100644
--- a/crypto/conf/conf_api.c
+++ b/crypto/conf/conf_api.c
@@ -241,8 +241,7 @@ static void value_free_stack_doall(CONF_VALUE *a)
OPENSSL_free(vv->name);
OPENSSL_free(vv);
}
- if (sk != NULL)
- sk_CONF_VALUE_free(sk);
+ sk_CONF_VALUE_free(sk);
OPENSSL_free(a->section);
OPENSSL_free(a);
}
@@ -251,7 +250,7 @@ static void value_free_stack_doall(CONF_VALUE *a)
CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
{
STACK_OF(CONF_VALUE) *sk = NULL;
- int ok = 0, i;
+ int i;
CONF_VALUE *v = NULL, *vv;
if ((sk = sk_CONF_VALUE_new_null()) == NULL)
@@ -268,13 +267,10 @@ CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
vv = lh_CONF_VALUE_insert(conf->data, v);
OPENSSL_assert(vv == NULL);
- ok = 1;
+ return v;
+
err:
- if (!ok) {
- if (sk != NULL)
- sk_CONF_VALUE_free(sk);
- OPENSSL_free(v);
- v = NULL;
- }
- return (v);
+ sk_CONF_VALUE_free(sk);
+ OPENSSL_free(v);
+ return NULL;
}
diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c
index ce2b177873..18fe38b302 100644
--- a/crypto/conf/conf_mod.c
+++ b/crypto/conf/conf_mod.c
@@ -266,8 +266,7 @@ static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
return md;
err:
- if (dso)
- DSO_free(dso);
+ DSO_free(dso);
CONFerr(CONF_F_MODULE_LOAD_DSO, errcode);
ERR_add_error_data(4, "module=", name, ", path=", path);
return NULL;
@@ -422,8 +421,7 @@ void CONF_modules_unload(int all)
/* unload a single module */
static void module_free(CONF_MODULE *md)
{
- if (md->dso)
- DSO_free(md->dso);
+ DSO_free(md->dso);
OPENSSL_free(md->name);
OPENSSL_free(md);
}
@@ -445,6 +443,8 @@ void CONF_modules_finish(void)
static void module_finish(CONF_IMODULE *imod)
{
+ if (!imod)
+ return;
if (imod->pmod->finish)
imod->pmod->finish(imod);
imod->pmod->links--;
diff --git a/crypto/dso/dso_lib.c b/crypto/dso/dso_lib.c
index a33a8a85bb..99701d15d4 100644
--- a/crypto/dso/dso_lib.c
+++ b/crypto/dso/dso_lib.c
@@ -133,10 +133,8 @@ int DSO_free(DSO *dso)
{
int i;
- if (dso == NULL) {
- DSOerr(DSO_F_DSO_FREE, ERR_R_PASSED_NULL_PARAMETER);
- return (0);
- }
+ if (dso == NULL)
+ return (1);
i = CRYPTO_add(&dso->references, -1, CRYPTO_LOCK_DSO);
#ifdef REF_PRINT
diff --git a/crypto/engine/eng_cnf.c b/crypto/engine/eng_cnf.c
index f09bec4e9a..e84281f22e 100644
--- a/crypto/engine/eng_cnf.c
+++ b/crypto/engine/eng_cnf.c
@@ -194,8 +194,7 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf)
", name=", ecmd->name,
", value=", ecmd->value);
}
- if (e)
- ENGINE_free(e);
+ ENGINE_free(e);
return ret;
}
diff --git a/crypto/engine/eng_dyn.c b/crypto/engine/eng_dyn.c
index 7dd3659e76..02590e026a 100644
--- a/crypto/engine/eng_dyn.c
+++ b/crypto/engine/eng_dyn.c
@@ -186,8 +186,7 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
{
if (ptr) {
dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr;
- if (ctx->dynamic_dso)
- DSO_free(ctx->dynamic_dso);
+ DSO_free(ctx->dynamic_dso);
OPENSSL_free(ctx->DYNAMIC_LIBNAME);
OPENSSL_free(ctx->engine_id);
if (ctx->dirs)
diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
index 608344064e..64b0cadb90 100644
--- a/crypto/engine/eng_lib.c
+++ b/crypto/engine/eng_lib.c
@@ -108,16 +108,14 @@ int engine_free_util(ENGINE *e, int locked)
{
int i;
- if (e == NULL) {
- ENGINEerr(ENGINE_F_ENGINE_FREE_UTIL, ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
+ if (e == NULL)
+ return 1;
if (locked)
i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE);
else
i = --e->struct_ref;
engine_ref_debug(e, 0, -1)
- if (i > 0)
+ if (i > 0)
return 1;
#ifdef REF_CHECK
if (i < 0) {
diff --git a/crypto/engine/eng_table.c b/crypto/engine/eng_table.c
index 53a6a25600..16eb771436 100644
--- a/crypto/engine/eng_table.c
+++ b/crypto/engine/eng_table.c
@@ -216,6 +216,8 @@ void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e)
static void int_cleanup_cb_doall(ENGINE_PILE *p)
{
+ if (!p)
+ return;
sk_ENGINE_free(p->sk);
if (p->funct)
engine_unlocked_finish(p->funct, 0);
diff --git a/crypto/err/err.c b/crypto/err/err.c
index 9d58f38144..308504a8ed 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -409,8 +409,7 @@ static void int_thread_del_item(const ERR_STATE *d)
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
int_thread_release(&hash);
- if (p)
- ERR_STATE_free(p);
+ ERR_STATE_free(p);
}
#ifndef OPENSSL_NO_ERR
@@ -905,8 +904,7 @@ ERR_STATE *ERR_get_state(void)
* If a race occurred in this function and we came second, tmpp is
* the first one that we just replaced.
*/
- if (tmpp)
- ERR_STATE_free(tmpp);
+ ERR_STATE_free(tmpp);
}
return ret;
}
diff --git a/crypto/objects/obj_xref.c b/crypto/objects/obj_xref.c
index 97b305d213..b752a2c5be 100644
--- a/crypto/objects/obj_xref.c
+++ b/crypto/objects/obj_xref.c
@@ -184,14 +184,10 @@ static void sid_free(nid_triple *tt)
void OBJ_sigid_free(void)
{
- if (sig_app) {
- sk_nid_triple_pop_free(sig_app, sid_free);
- sig_app = NULL;
- }
- if (sigx_app) {
- sk_nid_triple_free(sigx_app);
- sigx_app = NULL;
- }
+ sk_nid_triple_pop_free(sig_app, sid_free);
+ sig_app = NULL;
+ sk_nid_triple_free(sigx_app);
+ sigx_app = NULL;
}
#ifdef OBJ_XREF_TEST
diff --git a/crypto/ts/ts_asn1.c b/crypto/ts/ts_asn1.c
index 7c741d9691..99b686f39d 100644
--- a/crypto/ts/ts_asn1.c
+++ b/crypto/ts/ts_asn1.c
@@ -189,8 +189,7 @@ static int ts_resp_set_tst_info(TS_RESP *a)
TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_TOKEN_PRESENT);
return 0;
}
- if (a->tst_info != NULL)
- TS_TST_INFO_free(a->tst_info);
+ TS_TST_INFO_free(a->tst_info);
a->tst_info = PKCS7_to_TS_TST_INFO(a->token);
if (!a->tst_info) {
TSerr(TS_F_TS_RESP_SET_TST_INFO,
@@ -212,8 +211,7 @@ static int ts_resp_cb(int op, ASN1_VALUE **pval, const ASN1_ITEM *it,
if (op == ASN1_OP_NEW_POST) {
ts_resp->tst_info = NULL;
} else if (op == ASN1_OP_FREE_POST) {
- if (ts_resp->tst_info != NULL)
- TS_TST_INFO_free(ts_resp->tst_info);
+ TS_TST_INFO_free(ts_resp->tst_info);
} else if (op == ASN1_OP_D2I_POST) {
if (ts_resp_set_tst_info(ts_resp) == 0)
return 0;
diff --git a/crypto/ts/ts_conf.c b/crypto/ts/ts_conf.c
index 4716b2336d..2b85660209 100644
--- a/crypto/ts/ts_conf.c
+++ b/crypto/ts/ts_conf.c
@@ -230,8 +230,7 @@ int TS_CONF_set_default_engine(const char *name)
TSerr(TS_F_TS_CONF_SET_DEFAULT_ENGINE, TS_R_COULD_NOT_SET_ENGINE);
ERR_add_error_data(2, "engine:", name);
}
- if (e)
- ENGINE_free(e);
+ ENGINE_free(e);
return ret;
}