From 07f7b4b99d29da5f17d7a54340105586af855a04 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Tue, 10 Feb 2009 17:17:39 +0000 Subject: [PATCH] Fix a memory leak (unlikely to happen in practice) in krb5_mcc_store; use a cleanup handler for robustness. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21950 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/cc_memory.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/krb5/ccache/cc_memory.c b/src/lib/krb5/ccache/cc_memory.c index 2cfd60a10..61ab5451b 100644 --- a/src/lib/krb5/ccache/cc_memory.c +++ b/src/lib/krb5/ccache/cc_memory.c @@ -643,18 +643,19 @@ krb5_mcc_store(krb5_context ctx, krb5_ccache id, krb5_creds *creds) if (new_node == NULL) return ENOMEM; err = krb5_copy_creds(ctx, creds, &new_node->creds); - if (err) { - free(new_node); - return err; - } + if (err) + goto cleanup; err = k5_cc_mutex_lock(ctx, &mptr->lock); if (err) - return err; + goto cleanup; new_node->next = mptr->link; mptr->link = new_node; update_mcc_change_time(mptr); k5_cc_mutex_unlock(ctx, &mptr->lock); return 0; +cleanup: + free(new_node); + return err; } static krb5_error_code KRB5_CALLCONV -- 2.26.2