Fix memory leak by delaying instantiation of lid until it's needed
authorJustin Anderson <jander@mit.edu>
Tue, 4 Mar 2008 20:27:19 +0000 (20:27 +0000)
committerJustin Anderson <jander@mit.edu>
Tue, 4 Mar 2008 20:27:19 +0000 (20:27 +0000)
ticket: 5897
tags: pullup

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

src/lib/krb5/ccache/cc_memory.c

index 46fb6519fc1fb60e5e8b4e39526ba85a938d7f9f..173d0039d63c18ee74374a73ccdc158a59a5dc9d 100644 (file)
@@ -248,12 +248,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;
@@ -266,11 +260,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;