From 8aaafd0f1b5ce816e7996eca41a00f880b997897 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Wed, 18 Feb 2009 18:18:56 +0000 Subject: [PATCH] pull up r21890 from trunk ------------------------------------------------------------------------ r21890 | ghudson | 2009-02-05 13:19:23 -0500 (Thu, 05 Feb 2009) | 7 lines Changed paths: M /trunk/src/lib/krb5/keytab/ktbase.c ticket: 6367 tags: pullup target_version: 1.7 Fix a memory leak in krb5_kt_resolve when we fail to lock kt_typehead_lock. ------------------------------------------------------------------------ ticket: 6367 version_fixed: 1.7 status: resolved git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-7@22020 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