krb5 commit: Modernize exit path in gss_krb5int_copy_ccache()

Greg Hudson <[email protected]>
Newsgroups gmane.comp.encryption.kerberos.cvs
Message-ID <[email protected]>
https://github.com/krb5/krb5/commit/1b89e3d8e949f52901bce74c9afc7a1a64099520
commit 1b89e3d8e949f52901bce74c9afc7a1a64099520
Author: Robbie Harwood <[email protected]>
Date:   Thu May 2 14:32:33 2019 -0400

    Modernize exit path in gss_krb5int_copy_ccache()
    
    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 |   31 ++++++++++++-------------------
 1 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/lib/gssapi/krb5/copy_ccache.c b/src/lib/gssapi/krb5/copy_ccache.c
index 027ed48..2b2806e 100644
--- a/src/lib/gssapi/krb5/copy_ccache.c
+++ b/src/lib/gssapi/krb5/copy_ccache.c
@@ -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;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.