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);
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
#endif
return 0;
+
+err:
+ if (*session) {
+ gnutls_deinit(*session);
+ }
+ gnutls_certificate_free_credentials(*x509_cred);
+ return -1;
}