]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/commitdiff
Reduce duplication in initialize_tls_session_both().
authorSimon Ruderich <simon@ruderich.org>
Thu, 8 Aug 2013 19:18:39 +0000 (21:18 +0200)
committerSimon Ruderich <simon@ruderich.org>
Thu, 8 Aug 2013 19:18:39 +0000 (21:18 +0200)
src/connection.c

index 3254982b32b22f6dc2b2bf0c8dfcdece12fcc7cb..a860a494c2b18e7d1bbe04b9f8902d7d77b83272 100644 (file)
@@ -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;
 }