* set_ccache.c (gss_krb5_ccache_name): Don't make a copy of the string returned
authorKen Raeburn <raeburn@mit.edu>
Thu, 29 Jul 2004 01:50:02 +0000 (01:50 +0000)
committerKen Raeburn <raeburn@mit.edu>
Thu, 29 Jul 2004 01:50:02 +0000 (01:50 +0000)
by kg_get_ccache_name.  Simplify some calls using a temporary error code
variable.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16629 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/gssapi/krb5/ChangeLog
src/lib/gssapi/krb5/set_ccache.c

index c5f78eb3fd10e40414d0d1b496512b18c18e3d47..4bc52f823812c6a0f495ea701777e76a1759c943 100644 (file)
@@ -1,5 +1,9 @@
 2004-07-28  Ken Raeburn  <raeburn@mit.edu>
 
+       * set_ccache.c (gss_krb5_ccache_name): Don't make a copy of the
+       string returned by kg_get_ccache_name.  Simplify some calls using
+       a temporary error code variable.
+
        * gssapi_krb5.c (kg_get_ccache_name): Make a copy of the default
        ccache name, because calling krb5_free_context will destroy it.
        Make the copy always, not just in the local-context case.  Check
index 27422017bd9672db839ab807108edc174847fe52..810c7a050a0177ecfecda7baac22185953c39e96 100644 (file)
@@ -39,7 +39,6 @@ gss_krb5_ccache_name(minor_status, name, out_name)
     char *old_name = NULL;
     OM_uint32 err = 0;
     OM_uint32 minor = 0;
-
     char *gss_out_name;
 
     err = gssint_initialize_library();
@@ -54,46 +53,27 @@ gss_krb5_ccache_name(minor_status, name, out_name)
         const char *tmp_name = NULL;
 
         if (!err) {
-            if (GSS_ERROR(kg_get_ccache_name (&minor, &tmp_name))) {
-                err = minor;
-            }
-        }
-        
-        if (!err) {
-            old_name = malloc(strlen(tmp_name) + 1);
-            if (old_name == NULL) {
-                err = ENOMEM;
-            } else {
-                strcpy(old_name, tmp_name);
-            }
+            kg_get_ccache_name (&err, &tmp_name);
         }
-        
         if (!err) {
-           char *swap = NULL;
-
-            swap = gss_out_name;
-            gss_out_name = old_name;
-            old_name = swap;
+            old_name = gss_out_name;
+            gss_out_name = tmp_name;
         }            
     }
-    
-    if (!err) {
-        if (GSS_ERROR(kg_set_ccache_name (&minor, name))) {
-            err = minor;
-        }
-    }
+    /* If out_name was NULL, we keep the same gss_out_name value, and
+       don't free up any storage (leave old_name NULL).  */
+
+    if (!err)
+        kg_set_ccache_name (&err, name);
 
     minor = k5_setspecific(K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME, gss_out_name);
     if (minor) {
        /* Um.  Now what?  */
        if (err == 0) {
            err = minor;
-           if (out_name != NULL) {
-               *out_name = NULL;
-               out_name = NULL;
-           }
        }
        free(gss_out_name);
+       gss_out_name = NULL;
     }
 
     if (!err) {