From 895cba195a0c8430dcc8d1aa22b75eccaaee8f49 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Thu, 30 Apr 2015 18:10:52 -0400 Subject: [PATCH] free cleanup 12 Don't check for NULL before calling free function. This gets: NAME_CONSTRAINTS_free GENERAL_SUBTREE_free ECDSA_METHOD_free JPAKE_CTX_free OCSP_REQ_CTX_free SCT_free SRP_VBASE_free SRP_gN_free SRP_user_pwd_free TXT_DB_free Reviewed-by: Richard Levitte --- apps/apps.c | 9 +++------ apps/ocsp.c | 3 +-- crypto/ecdsa/ecs_lib.c | 2 ++ crypto/jpake/jpake.c | 2 ++ crypto/ocsp/ocsp_ht.c | 2 ++ crypto/srp/srp_vfy.c | 11 ++++++----- crypto/x509v3/v3_ncons.c | 6 ++---- crypto/x509v3/v3_scts.c | 10 +++++----- include/openssl/srp.h | 2 +- 9 files changed, 24 insertions(+), 23 deletions(-) diff --git a/apps/apps.c b/apps/apps.c index aecd6120f9..904629b2f1 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -600,8 +600,7 @@ int load_cert_crl_http(const char *url, X509 **pcert, X509_CRL **pcrl) OPENSSL_free(port); if (bio) BIO_free_all(bio); - if (rctx) - OCSP_REQ_CTX_free(rctx); + OCSP_REQ_CTX_free(rctx); if (rv != 1) { BIO_printf(bio_err, "Error loading %s from %s\n", pcert ? "certificate" : "CRL", url); @@ -1614,8 +1613,7 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr) err: if (dbattr_conf) NCONF_free(dbattr_conf); - if (tmpdb) - TXT_DB_free(tmpdb); + TXT_DB_free(tmpdb); BIO_free_all(in); return retdb; } @@ -1793,8 +1791,7 @@ int rotate_index(const char *dbfile, const char *new_suffix, void free_index(CA_DB *db) { if (db) { - if (db->db) - TXT_DB_free(db->db); + TXT_DB_free(db->db); OPENSSL_free(db); } } diff --git a/apps/ocsp.c b/apps/ocsp.c index 680cc0a79e..20dc1ae4cc 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -1229,8 +1229,7 @@ static OCSP_RESPONSE *query_responder(BIO *cbio, const char *path, } err: - if (ctx) - OCSP_REQ_CTX_free(ctx); + OCSP_REQ_CTX_free(ctx); return rsp; } diff --git a/crypto/ecdsa/ecs_lib.c b/crypto/ecdsa/ecs_lib.c index 55324f7fef..3d012120f6 100644 --- a/crypto/ecdsa/ecs_lib.c +++ b/crypto/ecdsa/ecs_lib.c @@ -312,6 +312,8 @@ void ECDSA_METHOD_set_name(ECDSA_METHOD *ecdsa_method, char *name) void ECDSA_METHOD_free(ECDSA_METHOD *ecdsa_method) { + if (!ecdsa_method) + return; if (ecdsa_method->flags & ECDSA_METHOD_FLAG_ALLOCATED) OPENSSL_free(ecdsa_method); } diff --git a/crypto/jpake/jpake.c b/crypto/jpake/jpake.c index eb6654d44f..b097c7f535 100644 --- a/crypto/jpake/jpake.c +++ b/crypto/jpake/jpake.c @@ -125,6 +125,8 @@ JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name, void JPAKE_CTX_free(JPAKE_CTX *ctx) { + if (!ctx) + return; JPAKE_CTX_release(ctx); OPENSSL_free(ctx); } diff --git a/crypto/ocsp/ocsp_ht.c b/crypto/ocsp/ocsp_ht.c index 4a06a8e1ef..266b43b00a 100644 --- a/crypto/ocsp/ocsp_ht.c +++ b/crypto/ocsp/ocsp_ht.c @@ -136,6 +136,8 @@ OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline) void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx) { + if (!rctx) + return; BIO_free(rctx->mem); if (rctx->iobuf) OPENSSL_free(rctx->iobuf); diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c index e8bdbf58b1..cd07f702c5 100644 --- a/crypto/srp/srp_vfy.c +++ b/crypto/srp/srp_vfy.c @@ -270,13 +270,14 @@ SRP_VBASE *SRP_VBASE_new(char *seed_key) return vb; } -int SRP_VBASE_free(SRP_VBASE *vb) +void SRP_VBASE_free(SRP_VBASE *vb) { + if (!vb) + return; sk_SRP_user_pwd_pop_free(vb->users_pwd, SRP_user_pwd_free); sk_SRP_gN_cache_free(vb->gN_cache); OPENSSL_free(vb->seed_key); OPENSSL_free(vb); - return 0; } static SRP_gN_cache *SRP_gN_new_init(const char *ch) @@ -457,8 +458,7 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) SRP_user_pwd_free(user_pwd); - if (tmpdb) - TXT_DB_free(tmpdb); + TXT_DB_free(tmpdb); BIO_free_all(in); sk_SRP_gN_free(SRP_gN_tab); @@ -509,7 +509,8 @@ SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username) BN_bin2bn(digv, SHA_DIGEST_LENGTH, NULL))) return user; - err:SRP_user_pwd_free(user); + err: + SRP_user_pwd_free(user); return NULL; } diff --git a/crypto/x509v3/v3_ncons.c b/crypto/x509v3/v3_ncons.c index c66e08042d..1e6fae8081 100644 --- a/crypto/x509v3/v3_ncons.c +++ b/crypto/x509v3/v3_ncons.c @@ -149,10 +149,8 @@ static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, memerr: X509V3err(X509V3_F_V2I_NAME_CONSTRAINTS, ERR_R_MALLOC_FAILURE); err: - if (ncons) - NAME_CONSTRAINTS_free(ncons); - if (sub) - GENERAL_SUBTREE_free(sub); + NAME_CONSTRAINTS_free(ncons); + GENERAL_SUBTREE_free(sub); return NULL; } diff --git a/crypto/x509v3/v3_scts.c b/crypto/x509v3/v3_scts.c index e70d5e927f..ecfc68dcb7 100644 --- a/crypto/x509v3/v3_scts.c +++ b/crypto/x509v3/v3_scts.c @@ -161,11 +161,11 @@ static void timestamp_print(BIO *out, SCT_TIMESTAMP timestamp) static void SCT_free(SCT *sct) { - if (sct) { - if (sct->sct) - OPENSSL_free(sct->sct); - OPENSSL_free(sct); - } + if (!sct) + return; + if (sct->sct) + OPENSSL_free(sct->sct); + OPENSSL_free(sct); } static void SCT_LIST_free(STACK_OF(SCT) *a) diff --git a/include/openssl/srp.h b/include/openssl/srp.h index 49cf960347..de6631d94f 100644 --- a/include/openssl/srp.h +++ b/include/openssl/srp.h @@ -113,7 +113,7 @@ typedef struct SRP_gN_st { DECLARE_STACK_OF(SRP_gN) SRP_VBASE *SRP_VBASE_new(char *seed_key); -int SRP_VBASE_free(SRP_VBASE *vb); +void SRP_VBASE_free(SRP_VBASE *vb); int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file); SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username); char *SRP_create_verifier(const char *user, const char *pass, char **salt, -- 2.40.0