From f4e57e4334f2676c5db9ee34cc7b158327ddedf7 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Tue, 4 Mar 2008 20:27:19 +0000 Subject: [PATCH] Fix memory leak by delaying instantiation of lid until it's needed 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 | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/krb5/ccache/cc_memory.c b/src/lib/krb5/ccache/cc_memory.c index 46fb6519f..173d0039d 100644 --- a/src/lib/krb5/ccache/cc_memory.c +++ b/src/lib/krb5/ccache/cc_memory.c @@ -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; -- 2.26.2