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>
This commit is contained in:
Rich Salz 2015-05-01 10:15:18 -04:00
parent b548a1f11c
commit efa7dd6444
32 changed files with 67 additions and 121 deletions

View File

@ -1612,8 +1612,7 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr)
}
err:
if (dbattr_conf)
NCONF_free(dbattr_conf);
NCONF_free(dbattr_conf);
TXT_DB_free(tmpdb);
BIO_free_all(in);
return retdb;

View File

@ -883,8 +883,7 @@ int req_main(int argc, char **argv)
if (sigopts)
sk_OPENSSL_STRING_free(sigopts);
#ifndef OPENSSL_NO_ENGINE
if (gen_eng)
ENGINE_free(gen_eng);
ENGINE_free(gen_eng);
#endif
OPENSSL_free(keyalgstr);
X509_REQ_free(req);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -363,9 +363,7 @@ int cluster_labs_init(ENGINE *e)
err:
/* reset all pointers */
if (cluster_labs_dso)
DSO_free(cluster_labs_dso);
DSO_free(cluster_labs_dso);
cluster_labs_dso = NULL;
p_cl_engine_init = NULL;
p_cl_mod_exp = NULL;

View File

@ -412,9 +412,7 @@ static int ibmca_init(ENGINE *e)
return 1;
err:
if (ibmca_dso)
DSO_free(ibmca_dso);
DSO_free(ibmca_dso);
p_icaOpenAdapter = NULL;
p_icaCloseAdapter = NULL;
p_icaRsaModExpo = NULL;

View File

@ -623,9 +623,7 @@ static int zencod_init(ENGINE *e)
return 1;
err:
if (zencod_dso) {
DSO_free(zencod_dso);
}
DSO_free(zencod_dso);
zencod_dso = NULL;
ptr_zencod_bytes2bits = NULL;
ptr_zencod_bits2bytes = NULL;

View File

@ -324,8 +324,7 @@ static int ibm_4758_cca_init(ENGINE *e)
return 1;
err:
if (dso)
DSO_free(dso);
DSO_free(dso);
dso = NULL;
# ifndef OPENSSL_NO_RSA

View File

@ -501,8 +501,7 @@ static int aep_init(ENGINE *e)
err:
if (aep_dso)
DSO_free(aep_dso);
DSO_free(aep_dso);
aep_dso = NULL;
p_AEP_OpenConnection = NULL;

View File

@ -406,8 +406,7 @@ static int atalla_init(ENGINE *e)
/* Everything's fine. */
return 1;
err:
if (atalla_dso)
DSO_free(atalla_dso);
DSO_free(atalla_dso);
atalla_dso = NULL;
p_Atalla_GetHardwareConfig = NULL;
p_Atalla_RSAPrivateKeyOpFn = NULL;

View File

@ -622,8 +622,7 @@ static int hwcrhk_init(ENGINE *e)
# endif
return 1;
err:
if (hwcrhk_dso)
DSO_free(hwcrhk_dso);
DSO_free(hwcrhk_dso);
hwcrhk_dso = NULL;
p_hwcrhk_Init = NULL;
p_hwcrhk_Finish = NULL;

View File

@ -431,10 +431,8 @@ static int cswift_init(ENGINE *e)
/* Everything's fine. */
return 1;
err:
if (cswift_dso) {
DSO_free(cswift_dso);
cswift_dso = NULL;
}
DSO_free(cswift_dso);
cswift_dso = NULL;
p_CSwift_AcquireAccContext = NULL;
p_CSwift_AttachKeyParam = NULL;
p_CSwift_SimpleRequest = NULL;

View File

@ -560,8 +560,7 @@ static int surewarehk_init(ENGINE *e)
return 1;
err:
if (surewarehk_dso)
DSO_free(surewarehk_dso);
DSO_free(surewarehk_dso);
surewarehk_dso = NULL;
p_surewarehk_Init = NULL;
p_surewarehk_Finish = NULL;

View File

@ -481,8 +481,7 @@ static int ubsec_init(ENGINE *e)
}
err:
if (ubsec_dso)
DSO_free(ubsec_dso);
DSO_free(ubsec_dso);
ubsec_dso = NULL;
p_UBSEC_ubsec_bytes_to_bits = NULL;
p_UBSEC_ubsec_bits_to_bytes = NULL;

View File

@ -259,10 +259,8 @@ int ssl3_change_cipher_state(SSL *s, int which)
}
#ifndef OPENSSL_NO_COMP
/* COMPRESS */
if (s->expand != NULL) {
COMP_CTX_free(s->expand);
s->expand = NULL;
}
COMP_CTX_free(s->expand);
s->expand = NULL;
if (comp != NULL) {
s->expand = COMP_CTX_new(comp);
if (s->expand == NULL) {
@ -294,10 +292,8 @@ int ssl3_change_cipher_state(SSL *s, int which)
}
#ifndef OPENSSL_NO_COMP
/* COMPRESS */
if (s->compress != NULL) {
COMP_CTX_free(s->compress);
s->compress = NULL;
}
COMP_CTX_free(s->compress);
s->compress = NULL;
if (comp != NULL) {
s->compress = COMP_CTX_new(comp);
if (s->compress == NULL) {

View File

@ -2860,14 +2860,10 @@ void ssl_clear_cipher_ctx(SSL *s)
s->enc_write_ctx = NULL;
}
#ifndef OPENSSL_NO_COMP
if (s->expand != NULL) {
COMP_CTX_free(s->expand);
s->expand = NULL;
}
if (s->compress != NULL) {
COMP_CTX_free(s->compress);
s->compress = NULL;
}
COMP_CTX_free(s->expand);
s->expand = NULL;
COMP_CTX_free(s->compress);
s->compress = NULL;
#endif
}

View File

@ -385,10 +385,8 @@ int tls1_change_cipher_state(SSL *s, int which)
dd = s->enc_read_ctx;
mac_ctx = ssl_replace_hash(&s->read_hash, NULL);
#ifndef OPENSSL_NO_COMP
if (s->expand != NULL) {
COMP_CTX_free(s->expand);
s->expand = NULL;
}
COMP_CTX_free(s->expand);
s->expand = NULL;
if (comp != NULL) {
s->expand = COMP_CTX_new(comp->method);
if (s->expand == NULL) {
@ -425,10 +423,8 @@ int tls1_change_cipher_state(SSL *s, int which)
} else
mac_ctx = ssl_replace_hash(&s->write_hash, NULL);
#ifndef OPENSSL_NO_COMP
if (s->compress != NULL) {
COMP_CTX_free(s->compress);
s->compress = NULL;
}
COMP_CTX_free(s->compress);
s->compress = NULL;
if (comp != NULL) {
s->compress = COMP_CTX_new(comp->method);
if (s->compress == NULL) {

View File

@ -147,8 +147,7 @@ int main(int argc, char *argv[])
printf("Remove failed!\n");
goto end;
}
if (ptr)
ENGINE_free(ptr);
ENGINE_free(ptr);
display_engine_list();
if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) {
printf("Add failed!\n");
@ -196,8 +195,7 @@ int main(int argc, char *argv[])
if (!ENGINE_remove(ptr))
printf("Remove failed!i - probably no hardware "
"support present.\n");
if (ptr)
ENGINE_free(ptr);
ENGINE_free(ptr);
display_engine_list();
if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) {
printf("Couldn't add and remove to an empty list!\n");
@ -248,17 +246,12 @@ int main(int argc, char *argv[])
end:
if (to_return)
ERR_print_errors_fp(stderr);
if (new_h1)
ENGINE_free(new_h1);
if (new_h2)
ENGINE_free(new_h2);
if (new_h3)
ENGINE_free(new_h3);
if (new_h4)
ENGINE_free(new_h4);
ENGINE_free(new_h1);
ENGINE_free(new_h2);
ENGINE_free(new_h3);
ENGINE_free(new_h4);
for (loop = 0; loop < 512; loop++)
if (block[loop])
ENGINE_free(block[loop]);
ENGINE_free(block[loop]);
ENGINE_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();