From ce0fb6678a4402fa1a41c88e1097e7501f4a4fef Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 7 Sep 2011 19:10:25 +0000 Subject: [PATCH] Fix some error-handling bugs in cc_dir.c git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25168 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/cc_dir.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/krb5/ccache/cc_dir.c b/src/lib/krb5/ccache/cc_dir.c index 6cd192a71..83427860f 100644 --- a/src/lib/krb5/ccache/cc_dir.c +++ b/src/lib/krb5/ccache/cc_dir.c @@ -184,7 +184,7 @@ write_primary_file(const char *primary_path, const char *contents) krb5_error_code ret = KRB5_CC_IO; char *newpath = NULL; FILE *fp = NULL; - int fd = -1; + int fd = -1, status; if (asprintf(&newpath, "%s.XXXXXX", primary_path) < 0) return ENOMEM; @@ -200,7 +200,9 @@ write_primary_file(const char *primary_path, const char *contents) fd = -1; if (fprintf(fp, "%s\n", contents) < 0) goto cleanup; - if (fclose(fp) == EOF) + status = fclose(fp); + fp = NULL; + if (status == EOF) goto cleanup; fp = NULL; if (rename(newpath, primary_path) != 0) @@ -365,7 +367,7 @@ dcc_gen_new(krb5_context context, krb5_ccache *cache_out) { krb5_error_code ret; char *dirname = NULL, *template = NULL, *residual = NULL; - krb5_ccache fcc; + krb5_ccache fcc = NULL; *cache_out = NULL; ret = get_context_default_dir(context, &dirname); @@ -390,9 +392,12 @@ dcc_gen_new(krb5_context context, krb5_ccache *cache_out) } ret = make_cache(residual, fcc, cache_out); if (ret) - krb5_fcc_ops.destroy(context, fcc); + goto cleanup; + fcc = NULL; cleanup: + if (fcc != NULL) + krb5_fcc_ops.destroy(context, fcc); free(dirname); free(template); free(residual); -- 2.26.2