pull up r20254 from trunk
authorTom Yu <tlyu@mit.edu>
Fri, 7 Mar 2008 20:43:42 +0000 (20:43 +0000)
committerTom Yu <tlyu@mit.edu>
Fri, 7 Mar 2008 20:43:42 +0000 (20:43 +0000)
 r20254@cathode-dark-space:  jander | 2008-03-04 15:27:19 -0500
 ticket: 5897
 tags: pullup

 Fix memory leak by delaying instantiation of lid until it's needed.

ticket: 5897
version_fixed: 1.6.4

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-6@20258 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/ccache/cc_memory.c

index 124548ce6f76ad259a6c585a9adaac0e6b162601..a289425e111720bc0ed5d10c760be9abde791048 100644 (file)
@@ -244,12 +244,6 @@ krb5_mcc_resolve (krb5_context context, krb5_ccache *id, const char *residual)
     krb5_error_code err;
     krb5_mcc_data *d;
 
-    lid = (krb5_ccache) malloc(sizeof(struct _krb5_ccache));
-    if (lid == NULL)
-       return KRB5_CC_NOMEM;
-
-    lid->ops = &krb5_mcc_ops;
-
     err = k5_mutex_lock(&krb5int_mcc_mutex);
     if (err)
        return err;
@@ -262,11 +256,16 @@ krb5_mcc_resolve (krb5_context context, krb5_ccache *id, const char *residual)
        err = new_mcc_data(residual, &d);
        if (err) {
            k5_mutex_unlock(&krb5int_mcc_mutex);
-           krb5_xfree(lid);
            return err;
        }
     }
     k5_mutex_unlock(&krb5int_mcc_mutex);
+
+    lid = (krb5_ccache) malloc(sizeof(struct _krb5_ccache));
+    if (lid == NULL)
+       return KRB5_CC_NOMEM;
+    
+    lid->ops = &krb5_mcc_ops;
     lid->data = d;
     *id = lid; 
     return KRB5_OK;