From 5a66e8f96603b34497de8fed762a9ac41e929efa Mon Sep 17 00:00:00 2001 From: Jan Zeleny Date: Fri, 4 Nov 2011 04:11:03 -0400 Subject: Fixed possible resource leak in create_mail_spool() https://fedorahosted.org/sssd/ticket/1071 --- src/tools/tools_util.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c index fb4c4ef7..7dfdecf8 100644 --- a/src/tools/tools_util.c +++ b/src/tools/tools_util.c @@ -408,7 +408,7 @@ int create_mail_spool(TALLOC_CTX *mem_ctx, uid_t uid, gid_t gid) { char *spool_file = NULL; - int fd; + int fd = -1; int ret; spool_file = talloc_asprintf(mem_ctx, "%s/%s", maildir, username); @@ -448,18 +448,18 @@ int create_mail_spool(TALLOC_CTX *mem_ctx, ret = errno; DEBUG(1, ("Cannot fsync() the spool file: [%d][%s]\n", ret, strerror(ret))); - goto fail; } - ret = close(fd); - if (ret != 0) { - ret = errno; - DEBUG(1, ("Cannot close() the spool file: [%d][%s]\n", - ret, strerror(ret))); - goto fail; +fail: + if (fd >= 0) { + ret = close(fd); + if (ret != 0) { + ret = errno; + DEBUG(1, ("Cannot close() the spool file: [%d][%s]\n", + ret, strerror(ret))); + } } -fail: reset_selinux_file_context(); talloc_free(spool_file); return ret; -- cgit