svn rev #21896: trunk/src/lib/krb5/rcache/

ghudson@MIT.EDU ghudson at MIT.EDU
Thu Feb 5 14:44:38 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=21896
Commit By: ghudson
Log Message:
Change krb5_rc_resolve_type (not a public API) to allocate the rcache
structure.  Make output parameter values of krb5_rc_resolve_type and
krb5_rc_default well-defined in case of errors.



Changed Files:
U   trunk/src/lib/krb5/rcache/rc_base.c
U   trunk/src/lib/krb5/rcache/rc_dfl.c
Modified: trunk/src/lib/krb5/rcache/rc_base.c
===================================================================
--- trunk/src/lib/krb5/rcache/rc_base.c	2009-02-05 19:02:29 UTC (rev 21895)
+++ trunk/src/lib/krb5/rcache/rc_base.c	2009-02-05 19:44:35 UTC (rev 21896)
@@ -64,24 +64,39 @@
     return 0;
 }
 
-krb5_error_code krb5_rc_resolve_type(krb5_context context, krb5_rcache *id,
+krb5_error_code krb5_rc_resolve_type(krb5_context context, krb5_rcache *idptr,
                                      char *type)
 {
     struct krb5_rc_typelist *t;
     krb5_error_code err;
+    krb5_rcache id;
+
+    *idptr = NULL;
+
+    /* Find the named type in the list. */
     err = k5_mutex_lock(&rc_typelist_lock);
     if (err)
         return err;
-    for (t = typehead;t && strcmp(t->ops->type,type);t = t->next)
+    for (t = typehead; t && strcmp(t->ops->type, type); t = t->next)
         ;
-    if (!t) {
-        k5_mutex_unlock(&rc_typelist_lock);
+    k5_mutex_unlock(&rc_typelist_lock);
+    if (!t)
         return KRB5_RC_TYPE_NOTFOUND;
+
+    /* Create and return the rcache structure. */
+    id = malloc(sizeof(*id));
+    if (!id)
+        return KRB5_RC_MALLOC;
+    err = k5_mutex_init(&id->lock);
+    if (err) {
+        free(id);
+        return err;
     }
-    /* allocate *id? nah */
-    (*id)->ops = t->ops;
-    k5_mutex_unlock(&rc_typelist_lock);
-    return k5_mutex_init(&(*id)->lock);
+    id->data = NULL;  /* Gets real data when resolved */
+    id->magic = 0;    /* Gets real magic after resolved */
+    id->ops = t->ops;
+    *idptr = id;
+    return 0;
 }
 
 char * krb5_rc_get_type(krb5_context context, krb5_rcache id)
@@ -108,25 +123,23 @@
 }
 
 krb5_error_code
-krb5_rc_default(krb5_context context, krb5_rcache *id)
+krb5_rc_default(krb5_context context, krb5_rcache *idptr)
 {
     krb5_error_code retval;
+    krb5_rcache id;
 
-    if (!(*id = (krb5_rcache )malloc(sizeof(**id))))
-        return KRB5_RC_MALLOC;
-
-    if ((retval = krb5_rc_resolve_type(context, id,
-                                       krb5_rc_default_type(context)))) {
-        free(*id);
+    *idptr = NULL;
+    retval = krb5_rc_resolve_type(context, &id, krb5_rc_default_type(context));
+    if (retval)
         return retval;
-    }
-    if ((retval = krb5_rc_resolve(context, *id,
-                                  krb5_rc_default_name(context)))) {
-        k5_mutex_destroy(&(*id)->lock);
-        free(*id);
+    retval = krb5_rc_resolve(context, id, krb5_rc_default_name(context));
+    if (retval) {
+        k5_mutex_destroy(&id->lock);
+        free(id);
         return retval;
     }
-    (*id)->magic = KV5M_RCACHE;
+    id->magic = KV5M_RCACHE;
+    *idptr = id;
     return retval;
 }
 
@@ -151,17 +164,10 @@
     (void) strncpy(type, string_name, diff);
     type[residual - string_name] = '\0';
 
-    if (!(id = (krb5_rcache) malloc(sizeof(*id)))) {
-        free(type);
-        return KRB5_RC_MALLOC;
-    }
-
-    if ((retval = krb5_rc_resolve_type(context, &id,type))) {
-        free(type);
-        free(id);
+    retval = krb5_rc_resolve_type(context, &id,type);
+    free(type);
+    if (retval)
         return retval;
-    }
-    free(type);
     if ((retval = krb5_rc_resolve(context, id,residual + 1))) {
         k5_mutex_destroy(&id->lock);
         free(id);

Modified: trunk/src/lib/krb5/rcache/rc_dfl.c
===================================================================
--- trunk/src/lib/krb5/rcache/rc_dfl.c	2009-02-05 19:02:29 UTC (rev 21895)
+++ trunk/src/lib/krb5/rcache/rc_dfl.c	2009-02-05 19:44:35 UTC (rev 21896)
@@ -826,14 +826,9 @@
         t = (struct dfl_data *)id->data; /* point to recovered cache */
     }
 
-    tmp = (krb5_rcache) malloc(sizeof(*tmp));
-    if (!tmp)
-        return ENOMEM;
     retval = krb5_rc_resolve_type(context, &tmp, "dfl");
-    if (retval) {
-        free(tmp);
+    if (retval)
         return retval;
-    }
     retval = krb5_rc_resolve(context, tmp, 0);
     if (retval)
         goto cleanup;




More information about the cvs-krb5 mailing list