]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Modernize exit path in gss_krb5int_copy_ccache()
authorRobbie Harwood <rharwood@redhat.com>
Thu, 2 May 2019 18:32:33 +0000 (14:32 -0400)
committerGreg Hudson <ghudson@mit.edu>
Mon, 6 May 2019 16:34:22 +0000 (12:34 -0400)
Move to a single lock / single unlock paradigm, and eliminate some
dead code in the old error handling.

src/lib/gssapi/krb5/copy_ccache.c

index 027ed4847476bb0d82992ecf0d89c3e0568b022e..2b2806e705e4fa8900902cc5e472d34143b4d6ab 100644 (file)
@@ -9,7 +9,7 @@ gss_krb5int_copy_ccache(OM_uint32 *minor_status,
 {
     krb5_gss_cred_id_t k5creds;
     krb5_error_code code;
-    krb5_context context;
+    krb5_context context = NULL;
     krb5_ccache out_ccache;
 
     assert(value->length == sizeof(out_ccache));
@@ -23,30 +23,23 @@ gss_krb5int_copy_ccache(OM_uint32 *minor_status,
     k5creds = (krb5_gss_cred_id_t) *cred_handle;
     k5_mutex_lock(&k5creds->lock);
     if (k5creds->usage == GSS_C_ACCEPT) {
-        k5_mutex_unlock(&k5creds->lock);
-        *minor_status = (OM_uint32) G_BAD_USAGE;
-        return(GSS_S_FAILURE);
+        code = G_BAD_USAGE;
+        goto cleanup;
     }
 
     code = krb5_gss_init_context(&context);
-    if (code) {
-        k5_mutex_unlock(&k5creds->lock);
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    if (code)
+        goto cleanup;
 
     code = krb5_cc_copy_creds(context, k5creds->ccache, out_ccache);
-    if (code) {
-        k5_mutex_unlock(&k5creds->lock);
-        *minor_status = code;
-        save_error_info(*minor_status, context);
-        krb5_free_context(context);
-        return(GSS_S_FAILURE);
-    }
+
+cleanup:
     k5_mutex_unlock(&k5creds->lock);
     *minor_status = code;
-    if (code)
-        save_error_info(*minor_status, context);
-    krb5_free_context(context);
+    if (context != NULL) {
+        if (code)
+            save_error_info(*minor_status, context);
+        krb5_free_context(context);
+    }
     return code ? GSS_S_FAILURE : GSS_S_COMPLETE;
 }