free NULL cleanup 10

Avoid checking for NULL before calling free functions.  This gets
ssl.*free:
    ssl_sess_cert_free ssl_free ssl_excert_free ssl_cert_free
    SSL_free SSL_SRP_CTX_free SSL_SESSION_free SSL_CTX_free
    SSL_CTX_SRP_CTX_free SSL_CONF_CTX_free

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
This commit is contained in:
Rich Salz 2015-04-11 10:22:36 -04:00
parent e2010b202a
commit 62adbcee39
16 changed files with 30 additions and 47 deletions

View File

@ -223,9 +223,7 @@ int MAIN(int argc, char **argv)
end: end:
if (use_supported && sk) if (use_supported && sk)
sk_SSL_CIPHER_free(sk); sk_SSL_CIPHER_free(sk);
if (ctx != NULL)
SSL_CTX_free(ctx); SSL_CTX_free(ctx);
if (ssl != NULL)
SSL_free(ssl); SSL_free(ssl);
BIO_free_all(STDout); BIO_free_all(STDout);
apps_shutdown(); apps_shutdown();

View File

@ -1363,7 +1363,6 @@ OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
BIO_printf(bio_err, "Error querying OCSP responder\n"); BIO_printf(bio_err, "Error querying OCSP responder\n");
end: end:
BIO_free_all(cbio); BIO_free_all(cbio);
if (ctx)
SSL_CTX_free(ctx); SSL_CTX_free(ctx);
return resp; return resp;
} }

View File

@ -2024,7 +2024,6 @@ int MAIN(int argc, char **argv)
if (next_proto.data) if (next_proto.data)
OPENSSL_free(next_proto.data); OPENSSL_free(next_proto.data);
#endif #endif
if (ctx != NULL)
SSL_CTX_free(ctx); SSL_CTX_free(ctx);
if (cert) if (cert)
X509_free(cert); X509_free(cert);
@ -2040,7 +2039,6 @@ int MAIN(int argc, char **argv)
ssl_excert_free(exc); ssl_excert_free(exc);
if (ssl_args) if (ssl_args)
sk_OPENSSL_STRING_free(ssl_args); sk_OPENSSL_STRING_free(ssl_args);
if (cctx)
SSL_CONF_CTX_free(cctx); SSL_CONF_CTX_free(cctx);
#ifndef OPENSSL_NO_JPAKE #ifndef OPENSSL_NO_JPAKE
if (jpake_secret && psk_key) if (jpake_secret && psk_key)

View File

@ -2003,7 +2003,6 @@ int MAIN(int argc, char *argv[])
print_stats(bio_s_out, ctx); print_stats(bio_s_out, ctx);
ret = 0; ret = 0;
end: end:
if (ctx != NULL)
SSL_CTX_free(ctx); SSL_CTX_free(ctx);
if (s_cert) if (s_cert)
X509_free(s_cert); X509_free(s_cert);
@ -2031,7 +2030,6 @@ int MAIN(int argc, char *argv[])
OPENSSL_free(tlscstatp.port); OPENSSL_free(tlscstatp.port);
if (tlscstatp.path) if (tlscstatp.path)
OPENSSL_free(tlscstatp.path); OPENSSL_free(tlscstatp.path);
if (ctx2 != NULL)
SSL_CTX_free(ctx2); SSL_CTX_free(ctx2);
if (s_cert2) if (s_cert2)
X509_free(s_cert2); X509_free(s_cert2);
@ -2047,7 +2045,6 @@ int MAIN(int argc, char *argv[])
ssl_excert_free(exc); ssl_excert_free(exc);
if (ssl_args) if (ssl_args)
sk_OPENSSL_STRING_free(ssl_args); sk_OPENSSL_STRING_free(ssl_args);
if (cctx)
SSL_CONF_CTX_free(cctx); SSL_CONF_CTX_free(cctx);
#ifndef OPENSSL_NO_JPAKE #ifndef OPENSSL_NO_JPAKE
if (jpake_secret && psk_key) if (jpake_secret && psk_key)

View File

@ -540,13 +540,10 @@ int MAIN(int argc, char **argv)
ret = 0; ret = 0;
end: end:
if (scon != NULL)
SSL_free(scon); SSL_free(scon);
if (tm_ctx != NULL) {
SSL_CTX_free(tm_ctx); SSL_CTX_free(tm_ctx);
tm_ctx = NULL; tm_ctx = NULL;
}
apps_shutdown(); apps_shutdown();
OPENSSL_EXIT(ret); OPENSSL_EXIT(ret);
} }

View File

@ -106,7 +106,6 @@ char *argv[];
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
} }
BIO_free_all(out); BIO_free_all(out);
if (ssl_ctx != NULL)
SSL_CTX_free(ssl_ctx); SSL_CTX_free(ssl_ctx);
exit(!ret); exit(!ret);
return (ret); return (ret);

View File

@ -804,7 +804,6 @@ SSL_CTX *tls_create_ctx(struct tls_create_ctx_args a, void *apparg)
err: err:
tls_openssl_errors(err_pref_1, err_pref_2, NULL, apparg); tls_openssl_errors(err_pref_1, err_pref_2, NULL, apparg);
err_return: err_return:
if (ret != NULL)
SSL_CTX_free(ret); SSL_CTX_free(ret);
return NULL; return NULL;
} }

View File

@ -17,6 +17,7 @@ The function SSL_CONF_CTX_new() allocates and initialises an B<SSL_CONF_CTX>
structure for use with the SSL_CONF functions. structure for use with the SSL_CONF functions.
The function SSL_CONF_CTX_free() frees up the context B<cctx>. The function SSL_CONF_CTX_free() frees up the context B<cctx>.
If B<cctx> is NULL nothing is done.
=head1 RETURN VALUES =head1 RETURN VALUES

View File

@ -20,6 +20,8 @@ It also calls the free()ing procedures for indirectly affected items, if
applicable: the session cache, the list of ciphers, the list of Client CAs, applicable: the session cache, the list of ciphers, the list of Client CAs,
the certificates and keys. the certificates and keys.
If B<ctx> is NULL nothing is done.
=head1 WARNINGS =head1 WARNINGS
If a session-remove callback is set (SSL_CTX_sess_set_remove_cb()), this If a session-remove callback is set (SSL_CTX_sess_set_remove_cb()), this

View File

@ -15,6 +15,7 @@ SSL_SESSION_free - free an allocated SSL_SESSION structure
SSL_SESSION_free() decrements the reference count of B<session> and removes SSL_SESSION_free() decrements the reference count of B<session> and removes
the B<SSL_SESSION> structure pointed to by B<session> and frees up the allocated the B<SSL_SESSION> structure pointed to by B<session> and frees up the allocated
memory, if the reference count has reached 0. memory, if the reference count has reached 0.
If B<session> is NULL nothing is done.
=head1 NOTES =head1 NOTES

View File

@ -15,6 +15,7 @@ SSL_free - free an allocated SSL structure
SSL_free() decrements the reference count of B<ssl>, and removes the SSL SSL_free() decrements the reference count of B<ssl>, and removes the SSL
structure pointed to by B<ssl> and frees up the allocated memory if the structure pointed to by B<ssl> and frees up the allocated memory if the
reference count has reached 0. reference count has reached 0.
If B<ssl> is NULL nothing is done.
=head1 NOTES =head1 NOTES

View File

@ -125,7 +125,7 @@ static int ssl_free(BIO *a)
if (bs->ssl != NULL) if (bs->ssl != NULL)
SSL_shutdown(bs->ssl); SSL_shutdown(bs->ssl);
if (a->shutdown) { if (a->shutdown) {
if (a->init && (bs->ssl != NULL)) if (a->init)
SSL_free(bs->ssl); SSL_free(bs->ssl);
a->init = 0; a->init = 0;
a->flags = 0; a->flags = 0;
@ -416,7 +416,6 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
break; break;
case BIO_CTRL_DUP: case BIO_CTRL_DUP:
dbio = (BIO *)ptr; dbio = (BIO *)ptr;
if (((BIO_SSL *)dbio->ptr)->ssl != NULL)
SSL_free(((BIO_SSL *)dbio->ptr)->ssl); SSL_free(((BIO_SSL *)dbio->ptr)->ssl);
((BIO_SSL *)dbio->ptr)->ssl = SSL_dup(ssl); ((BIO_SSL *)dbio->ptr)->ssl = SSL_dup(ssl);
((BIO_SSL *)dbio->ptr)->renegotiate_count = ((BIO_SSL *)dbio->ptr)->renegotiate_count =

View File

@ -1215,7 +1215,6 @@ int ssl3_get_server_certificate(SSL *s)
if (sc == NULL) if (sc == NULL)
goto err; goto err;
if (s->session->sess_cert)
ssl_sess_cert_free(s->session->sess_cert); ssl_sess_cert_free(s->session->sess_cert);
s->session->sess_cert = sc; s->session->sess_cert = sc;

View File

@ -393,7 +393,6 @@ SSL *SSL_new(SSL_CTX *ctx)
return (s); return (s);
err: err:
if (s != NULL)
SSL_free(s); SSL_free(s);
SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE); SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);
return (NULL); return (NULL);
@ -2992,6 +2991,7 @@ int ssl_init_wbio_buffer(SSL *s, int push)
void ssl_free_wbio_buffer(SSL *s) void ssl_free_wbio_buffer(SSL *s)
{ {
/* callers ensure s is never null */
if (s->bbio == NULL) if (s->bbio == NULL)
return; return;

View File

@ -292,10 +292,8 @@ int ssl_get_new_session(SSL *s, int session)
else else
ss->timeout = s->session_ctx->session_timeout; ss->timeout = s->session_ctx->session_timeout;
if (s->session != NULL) {
SSL_SESSION_free(s->session); SSL_SESSION_free(s->session);
s->session = NULL; s->session = NULL;
}
if (session) { if (session) {
if (s->version == SSL3_VERSION) { if (s->version == SSL3_VERSION) {
@ -578,7 +576,6 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
s->session_ctx->stats.sess_hit++; s->session_ctx->stats.sess_hit++;
if (s->session != NULL)
SSL_SESSION_free(s->session); SSL_SESSION_free(s->session);
s->session = ret; s->session = ret;
s->verify_result = s->session->verify_result; s->verify_result = s->session->verify_result;

View File

@ -1789,14 +1789,10 @@ int main(int argc, char *argv[])
SSL_free(c_ssl); SSL_free(c_ssl);
end: end:
if (s_ctx != NULL)
SSL_CTX_free(s_ctx); SSL_CTX_free(s_ctx);
if (c_ctx != NULL)
SSL_CTX_free(c_ctx); SSL_CTX_free(c_ctx);
if (s_cctx)
SSL_CONF_CTX_free(s_cctx); SSL_CONF_CTX_free(s_cctx);
if (c_cctx)
SSL_CONF_CTX_free(c_cctx); SSL_CONF_CTX_free(c_cctx);
sk_OPENSSL_STRING_free(conf_args); sk_OPENSSL_STRING_free(conf_args);