[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a better version...



Hello,

Sorry, this is a better version of the previous patch I sent that compiles 
much more cleanly.

Wynn
Index: cache.c
===================================================================
RCS file: /col/csm/cvs/VAS/src/heimdal/lib/krb5/cache.c,v
retrieving revision 1.2
diff -u -p -B -w -r1.2 cache.c
--- cache.c	2002/05/29 15:23:50	1.2
+++ cache.c	2002/05/30 00:01:30
@@ -100,18 +100,45 @@ allocate_ccache (krb5_context context,
                  krb5_ccache *id) 
 {
     krb5_error_code ret;
-    krb5_ccache p;
+    krb5_ccache     p = NULL;
+    krb5_cc_ops     *new_ops = NULL;
+
+        
+    /* we make a deep copy so the ccache does not become invalid
+       when the context is free'd. krb5_cc_close free's all this
+       memory
+     */
+    new_ops = malloc(sizeof(*ops));
+    if( new_ops == NULL ) {
+        krb5_set_error_string(context, "malloc: out of memory");
+        return KRB5_CC_NOMEM;
+    }
 
+    memcpy(new_ops, ops, sizeof(*ops));
+    new_ops->prefix = strdup( ops->prefix );
+    if( new_ops->prefix == NULL ) {
+        free((void*)new_ops);
+        krb5_set_error_string(context, "malloc: out of memory");
+        return KRB5_CC_NOMEM;
+    }
+
     p = malloc(sizeof(*p));
     if( p == NULL ) {
         krb5_set_error_string(context, "malloc: out of memory");
         return KRB5_CC_NOMEM;
     }
-    p->ops = ops;
+
+    memset( p, 0, sizeof(*p) );
+    p->ops = new_ops;
+
     *id = p;
     ret = p->ops->resolve(context, id, residual);
     if( ret )
+    {
+        free(new_ops->prefix);
+        free(new_ops);
         free(p);
+    }
     return ret;
 }
 
@@ -265,8 +292,14 @@ krb5_cc_close(krb5_context context,
               krb5_ccache id) 
 {
     krb5_error_code ret;
+
     ret = id->ops->close(context, id);
+    
+    /* free all the memory since it was a deep copy */
+    free(id->ops->prefix);
+    free((void*)id->ops);
     free(id);
+    
     return ret;
 }