From: Simon Ruderich Date: Thu, 8 Aug 2013 19:18:39 +0000 (+0200) Subject: Reduce duplication in initialize_tls_session_both(). X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=075cfe8260e8924bc62f08980e7034e439dddbcf;p=tlsproxy%2Ftlsproxy.git Reduce duplication in initialize_tls_session_both(). --- diff --git a/src/connection.c b/src/connection.c index 3254982..a860a49 100644 --- a/src/connection.c +++ b/src/connection.c @@ -463,22 +463,21 @@ static int initialize_tls_session_both(int flags, gnutls_certificate_credentials_t *x509_cred) { int result; + *session = NULL; + result = gnutls_init(session, flags); if (result != GNUTLS_E_SUCCESS) { LOG(ERROR, "initialize_tls_session_both(): gnutls_init(): %s", gnutls_strerror(result)); - gnutls_certificate_free_credentials(*x509_cred); - return -1; + goto err; } result = gnutls_priority_set(*session, global_tls_priority_cache); if (result != GNUTLS_E_SUCCESS) { LOG(ERROR, "initialize_tls_session_both(): gnutls_priority_set(): %s", gnutls_strerror(result)); - gnutls_deinit(*session); - gnutls_certificate_free_credentials(*x509_cred); - return -1; + goto err; } result = gnutls_credentials_set(*session, GNUTLS_CRD_CERTIFICATE, *x509_cred); @@ -486,9 +485,7 @@ static int initialize_tls_session_both(int flags, LOG(ERROR, "initialize_tls_session_both(): gnutls_credentials_set(): %s", gnutls_strerror(result)); - gnutls_deinit(*session); - gnutls_certificate_free_credentials(*x509_cred); - return -1; + goto err; } #ifdef HAVE_GNUTLS_TRANSPORT_SET_INT2 @@ -499,6 +496,13 @@ static int initialize_tls_session_both(int flags, #endif return 0; + +err: + if (*session) { + gnutls_deinit(*session); + } + gnutls_certificate_free_credentials(*x509_cred); + return -1; }