From 293242e87b276d9b56c03b5269781361f2b4acfc Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Thu, 5 Feb 2009 18:19:23 +0000 Subject: [PATCH] Fix a memory leak in krb5_kt_resolve when we fail to lock kt_typehead_lock. ticket: 6367 tags: pullup target_version: 1.7 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21890 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/keytab/ktbase.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/krb5/keytab/ktbase.c b/src/lib/krb5/keytab/ktbase.c index 9d5174540..a764cc593 100644 --- a/src/lib/krb5/keytab/ktbase.c +++ b/src/lib/krb5/keytab/ktbase.c @@ -162,10 +162,10 @@ krb5_error_code KRB5_CALLCONV krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) { const struct krb5_kt_typelist *tlist; - char *pfx; + char *pfx = NULL; unsigned int pfxlen; const char *cp, *resid; - krb5_error_code err; + krb5_error_code err = 0; cp = strchr (name, ':'); if (!cp) { @@ -201,7 +201,7 @@ krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) err = k5_mutex_lock(&kt_typehead_lock); if (err) - return err; + goto cleanup; tlist = kt_typehead; /* Don't need to hold the lock, since entries are never modified or removed once they're in the list. Just need to protect @@ -209,12 +209,15 @@ krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) k5_mutex_unlock(&kt_typehead_lock); for (; tlist; tlist = tlist->next) { if (strcmp (tlist->ops->prefix, pfx) == 0) { - free(pfx); - return (*tlist->ops->resolve)(context, resid, ktid); + err = (*tlist->ops->resolve)(context, resid, ktid); + goto cleanup; } } + err = KRB5_KT_UNKNOWN_TYPE; + +cleanup: free(pfx); - return KRB5_KT_UNKNOWN_TYPE; + return err; } /* -- 2.26.2